@nextgis/geocoder 1.11.8 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/geocoder.cjs.js +384 -135
- package/lib/geocoder.cjs.js.map +1 -1
- package/lib/geocoder.cjs.prod.js +1 -1
- package/lib/geocoder.cjs.prod.js.map +1 -1
- package/lib/geocoder.esm-browser.js +978 -598
- package/lib/geocoder.esm-browser.js.map +1 -1
- package/lib/geocoder.esm-browser.prod.js +15 -1
- package/lib/geocoder.esm-browser.prod.js.map +1 -1
- package/lib/geocoder.esm-bundler.js +384 -135
- package/lib/geocoder.esm-bundler.js.map +1 -1
- package/lib/geocoder.esm-bundler.prod.js +15 -1
- package/lib/geocoder.esm-bundler.prod.js.map +1 -1
- package/lib/geocoder.global.js +40 -15
- package/lib/geocoder.global.js.map +1 -1
- package/lib/geocoder.global.prod.js +1 -1
- package/lib/geocoder.global.prod.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,32 +1,167 @@
|
|
|
1
|
-
/** Bundle of @nextgis/geocoder; version: 1.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/** Bundle of @nextgis/geocoder; version: 1.12.1; author: NextGIS */
|
|
2
|
+
/*! *****************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
/* global Reflect, Promise */
|
|
17
|
+
|
|
18
|
+
var extendStatics = function(d, b) {
|
|
19
|
+
extendStatics = Object.setPrototypeOf ||
|
|
20
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
21
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
22
|
+
return extendStatics(d, b);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function __extends(d, b) {
|
|
26
|
+
if (typeof b !== "function" && b !== null)
|
|
27
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
28
|
+
extendStatics(d, b);
|
|
29
|
+
function __() { this.constructor = d; }
|
|
30
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var __assign = function() {
|
|
34
|
+
__assign = Object.assign || function __assign(t) {
|
|
35
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
36
|
+
s = arguments[i];
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
return __assign.apply(this, arguments);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
45
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function __generator(thisArg, body) {
|
|
55
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
56
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
57
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
58
|
+
function step(op) {
|
|
59
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
60
|
+
while (_) try {
|
|
61
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
62
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
63
|
+
switch (op[0]) {
|
|
64
|
+
case 0: case 1: t = op; break;
|
|
65
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
66
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
67
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
68
|
+
default:
|
|
69
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
70
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
71
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
72
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
73
|
+
if (t[2]) _.ops.pop();
|
|
74
|
+
_.trys.pop(); continue;
|
|
75
|
+
}
|
|
76
|
+
op = body.call(thisArg, _);
|
|
77
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
78
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function __values(o) {
|
|
83
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
84
|
+
if (m) return m.call(o);
|
|
85
|
+
if (o && typeof o.length === "number") return {
|
|
86
|
+
next: function () {
|
|
87
|
+
if (o && i >= o.length) o = void 0;
|
|
88
|
+
return { value: o && o[i++], done: !o };
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function __spreadArray(to, from, pack) {
|
|
95
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
96
|
+
if (ar || !(i in from)) {
|
|
97
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
98
|
+
ar[i] = from[i];
|
|
99
|
+
}
|
|
7
100
|
}
|
|
101
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function __await(v) {
|
|
105
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
109
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
110
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
111
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
112
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
113
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
114
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
115
|
+
function fulfill(value) { resume("next", value); }
|
|
116
|
+
function reject(value) { resume("throw", value); }
|
|
117
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function __asyncValues(o) {
|
|
121
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
122
|
+
var m = o[Symbol.asyncIterator], i;
|
|
123
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
124
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
125
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
126
|
}
|
|
9
127
|
|
|
10
|
-
class
|
|
11
|
-
|
|
128
|
+
var CancelError = /** @class */ (function (_super) {
|
|
129
|
+
__extends(CancelError, _super);
|
|
130
|
+
function CancelError() {
|
|
131
|
+
var _this = _super.call(this) || this;
|
|
132
|
+
_this.name = 'CancelError';
|
|
133
|
+
Object.setPrototypeOf(_this, CancelError.prototype);
|
|
134
|
+
return _this;
|
|
135
|
+
}
|
|
136
|
+
return CancelError;
|
|
137
|
+
}(Error));
|
|
138
|
+
|
|
139
|
+
var PromiseControl = /** @class */ (function () {
|
|
140
|
+
function PromiseControl(options) {
|
|
141
|
+
if (options === void 0) { options = {}; }
|
|
12
142
|
this.options = options;
|
|
13
143
|
this._promises = new Map();
|
|
14
144
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
145
|
+
Object.defineProperty(PromiseControl.prototype, "isLoaded", {
|
|
146
|
+
get: function () {
|
|
147
|
+
return this._promises.size > 0;
|
|
148
|
+
},
|
|
149
|
+
enumerable: false,
|
|
150
|
+
configurable: true
|
|
151
|
+
});
|
|
152
|
+
PromiseControl.prototype.remove = function (promise) {
|
|
19
153
|
if (this._promises.has(promise)) {
|
|
20
154
|
this._promises.delete(promise);
|
|
21
155
|
this._onStop();
|
|
22
156
|
}
|
|
23
|
-
}
|
|
24
|
-
get(promise) {
|
|
157
|
+
};
|
|
158
|
+
PromiseControl.prototype.get = function (promise) {
|
|
25
159
|
return this._promises.get(promise);
|
|
26
|
-
}
|
|
27
|
-
add(promise, name) {
|
|
28
|
-
|
|
29
|
-
|
|
160
|
+
};
|
|
161
|
+
PromiseControl.prototype.add = function (promise, name) {
|
|
162
|
+
var _this = this;
|
|
163
|
+
var key = name ? name : promise;
|
|
164
|
+
var exist = this._promises.get(key);
|
|
30
165
|
if (this.options.onStart && !this.isLoaded) {
|
|
31
166
|
this.options.onStart();
|
|
32
167
|
}
|
|
@@ -34,14 +169,14 @@ class PromiseControl {
|
|
|
34
169
|
return exist;
|
|
35
170
|
}
|
|
36
171
|
this._promises.set(key, promise);
|
|
37
|
-
promise.finally(()
|
|
38
|
-
|
|
172
|
+
promise.finally(function () {
|
|
173
|
+
_this.remove(key);
|
|
39
174
|
});
|
|
40
175
|
return promise;
|
|
41
|
-
}
|
|
42
|
-
abort() {
|
|
176
|
+
};
|
|
177
|
+
PromiseControl.prototype.abort = function () {
|
|
43
178
|
if (this.isLoaded) {
|
|
44
|
-
this._promises.forEach((x)
|
|
179
|
+
this._promises.forEach(function (x) {
|
|
45
180
|
if (x.cancel) {
|
|
46
181
|
x.cancel();
|
|
47
182
|
}
|
|
@@ -49,52 +184,63 @@ class PromiseControl {
|
|
|
49
184
|
this._promises.clear();
|
|
50
185
|
this._onStop();
|
|
51
186
|
}
|
|
52
|
-
}
|
|
53
|
-
waitFunc(func, name
|
|
187
|
+
};
|
|
188
|
+
PromiseControl.prototype.waitFunc = function (func, name) {
|
|
189
|
+
if (name === void 0) { name = ''; }
|
|
54
190
|
name = name || func.name;
|
|
55
|
-
|
|
191
|
+
var exist = this.get(name);
|
|
56
192
|
if (exist) {
|
|
57
193
|
return exist;
|
|
58
194
|
}
|
|
59
195
|
return this.add(func(), name);
|
|
60
|
-
}
|
|
61
|
-
WaitForMe
|
|
62
|
-
|
|
63
|
-
|
|
196
|
+
};
|
|
197
|
+
PromiseControl.prototype.WaitForMe = function (name) {
|
|
198
|
+
if (name === void 0) { name = ''; }
|
|
199
|
+
var get = this.get.bind(this);
|
|
200
|
+
var add = this.add.bind(this);
|
|
64
201
|
return function (target, key, descriptor) {
|
|
65
|
-
|
|
202
|
+
var originalMethod = descriptor.value;
|
|
66
203
|
name = name || key;
|
|
67
|
-
descriptor.value = function (
|
|
68
|
-
|
|
204
|
+
descriptor.value = function () {
|
|
205
|
+
var args = [];
|
|
206
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
207
|
+
args[_i] = arguments[_i];
|
|
208
|
+
}
|
|
209
|
+
var exist = get(name);
|
|
69
210
|
if (exist) {
|
|
70
211
|
return exist;
|
|
71
212
|
}
|
|
72
|
-
|
|
213
|
+
var result = add(originalMethod.apply(this, args), name);
|
|
73
214
|
return result;
|
|
74
215
|
};
|
|
75
216
|
return descriptor;
|
|
76
217
|
};
|
|
77
|
-
}
|
|
218
|
+
};
|
|
78
219
|
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
|
|
79
|
-
GetOrCreateDecorator
|
|
220
|
+
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
|
|
221
|
+
if (name === void 0) { name = ''; }
|
|
80
222
|
return this.WaitForMe(name);
|
|
81
|
-
}
|
|
82
|
-
_onStop() {
|
|
223
|
+
};
|
|
224
|
+
PromiseControl.prototype._onStop = function () {
|
|
83
225
|
if (this.options.onStop && !this.isLoaded) {
|
|
84
226
|
this.options.onStop();
|
|
85
227
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
228
|
+
};
|
|
229
|
+
return PromiseControl;
|
|
230
|
+
}());
|
|
88
231
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
232
|
+
var TimeoutError = /** @class */ (function (_super) {
|
|
233
|
+
__extends(TimeoutError, _super);
|
|
234
|
+
function TimeoutError() {
|
|
235
|
+
var _this = _super.call(this) || this;
|
|
236
|
+
_this.name = 'TimeoutError';
|
|
237
|
+
Object.setPrototypeOf(_this, TimeoutError.prototype);
|
|
238
|
+
return _this;
|
|
94
239
|
}
|
|
95
|
-
|
|
240
|
+
return TimeoutError;
|
|
241
|
+
}(Error));
|
|
96
242
|
|
|
97
|
-
|
|
243
|
+
var handleCallback = function (resolve, reject, callback, r) {
|
|
98
244
|
try {
|
|
99
245
|
resolve(callback(r));
|
|
100
246
|
}
|
|
@@ -102,7 +248,7 @@ const handleCallback = (resolve, reject, callback, r) => {
|
|
|
102
248
|
reject(e);
|
|
103
249
|
}
|
|
104
250
|
};
|
|
105
|
-
|
|
251
|
+
var ID$2 = 0;
|
|
106
252
|
/**
|
|
107
253
|
* Promise that can be canceled
|
|
108
254
|
*
|
|
@@ -147,48 +293,49 @@ let ID$2 = 0;
|
|
|
147
293
|
* promise.cancel();
|
|
148
294
|
* ```
|
|
149
295
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
296
|
+
var CancelablePromise$1 = /** @class */ (function () {
|
|
297
|
+
function CancelablePromise(executor, timeout) {
|
|
298
|
+
var _this = this;
|
|
152
299
|
this.id = ID$2++;
|
|
153
300
|
this._isCanceled = false;
|
|
154
301
|
this._isPending = true;
|
|
155
302
|
this._cancelHandlers = [];
|
|
156
303
|
this._children = [];
|
|
157
|
-
this._cancelPromise = new Promise((resolve_, reject_)
|
|
158
|
-
|
|
304
|
+
this._cancelPromise = new Promise(function (resolve_, reject_) {
|
|
305
|
+
_this._setCanceledCallback = function (er) { return resolve_(er || new CancelError()); };
|
|
159
306
|
});
|
|
160
|
-
|
|
307
|
+
var promises = [
|
|
161
308
|
this._cancelPromise,
|
|
162
|
-
new Promise((resolve, reject)
|
|
163
|
-
|
|
164
|
-
if (value instanceof CancelablePromise
|
|
165
|
-
|
|
309
|
+
new Promise(function (resolve, reject) {
|
|
310
|
+
var onResolve = function (value) {
|
|
311
|
+
if (value instanceof CancelablePromise) {
|
|
312
|
+
_this.attach(value);
|
|
166
313
|
}
|
|
167
314
|
else {
|
|
168
|
-
|
|
315
|
+
_this._isPending = false;
|
|
169
316
|
}
|
|
170
317
|
// TODO: fix types, `undefined` not allowed since 19.12.2020
|
|
171
318
|
resolve(value);
|
|
172
319
|
};
|
|
173
|
-
|
|
174
|
-
|
|
320
|
+
var onReject = function (error) {
|
|
321
|
+
_this._isPending = false;
|
|
175
322
|
reject(error);
|
|
176
323
|
};
|
|
177
|
-
|
|
178
|
-
if (!
|
|
324
|
+
var onCancel = function (handler) {
|
|
325
|
+
if (!_this._isPending) {
|
|
179
326
|
throw new Error('The `onCancel` handler was attached after the promise settled.');
|
|
180
327
|
}
|
|
181
|
-
|
|
328
|
+
_this._cancelHandlers.push(handler);
|
|
182
329
|
};
|
|
183
330
|
return executor(onResolve, onReject, onCancel);
|
|
184
331
|
}),
|
|
185
332
|
];
|
|
186
333
|
if (timeout) {
|
|
187
|
-
promises.push(new Promise((resolve, reject)
|
|
188
|
-
setTimeout(()
|
|
189
|
-
if (
|
|
334
|
+
promises.push(new Promise(function (resolve, reject) {
|
|
335
|
+
setTimeout(function () {
|
|
336
|
+
if (_this._isPending) {
|
|
190
337
|
try {
|
|
191
|
-
|
|
338
|
+
_this.cancel();
|
|
192
339
|
}
|
|
193
340
|
finally {
|
|
194
341
|
reject(new TimeoutError());
|
|
@@ -199,21 +346,23 @@ class CancelablePromise$1 {
|
|
|
199
346
|
}
|
|
200
347
|
this._promise = Promise.race(promises);
|
|
201
348
|
}
|
|
202
|
-
|
|
349
|
+
CancelablePromise.createControl = function (opt) {
|
|
203
350
|
return new PromiseControl(opt);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return new CancelablePromise
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return new CancelablePromise
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
351
|
+
};
|
|
352
|
+
CancelablePromise.resolve = function (value) {
|
|
353
|
+
return new CancelablePromise(function (resolve) { return resolve(value); });
|
|
354
|
+
};
|
|
355
|
+
CancelablePromise.reject = function (value) {
|
|
356
|
+
return new CancelablePromise(function (resolve, reject) { return reject(value); });
|
|
357
|
+
};
|
|
358
|
+
CancelablePromise.all = function (values) {
|
|
359
|
+
var _this = this;
|
|
360
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
213
361
|
Promise.all(values).then(resolve).catch(reject);
|
|
214
|
-
}).catch((er)
|
|
215
|
-
if (er instanceof
|
|
216
|
-
for (
|
|
362
|
+
}).catch(function (er) {
|
|
363
|
+
if (er instanceof _this.CancelError) {
|
|
364
|
+
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
365
|
+
var v = values_1[_i];
|
|
217
366
|
if ('cancel' in v) {
|
|
218
367
|
v.cancel();
|
|
219
368
|
}
|
|
@@ -221,19 +370,20 @@ class CancelablePromise$1 {
|
|
|
221
370
|
}
|
|
222
371
|
throw er;
|
|
223
372
|
});
|
|
224
|
-
}
|
|
225
|
-
attach(p) {
|
|
373
|
+
};
|
|
374
|
+
CancelablePromise.prototype.attach = function (p) {
|
|
226
375
|
if (this._isCanceled) {
|
|
227
376
|
p.cancel();
|
|
228
377
|
}
|
|
229
378
|
else {
|
|
230
379
|
this._children.push(p);
|
|
231
380
|
}
|
|
232
|
-
}
|
|
233
|
-
then(onfulfilled, onrejected) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
381
|
+
};
|
|
382
|
+
CancelablePromise.prototype.then = function (onfulfilled, onrejected) {
|
|
383
|
+
var _this = this;
|
|
384
|
+
var p = new CancelablePromise(function (resolve, reject) {
|
|
385
|
+
if (_this._promise) {
|
|
386
|
+
var reject_1 = function (r) {
|
|
237
387
|
if (onrejected) {
|
|
238
388
|
handleCallback(resolve, reject, onrejected, r);
|
|
239
389
|
}
|
|
@@ -241,9 +391,9 @@ class CancelablePromise$1 {
|
|
|
241
391
|
reject(r);
|
|
242
392
|
}
|
|
243
393
|
};
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
|
|
394
|
+
_this._promise.then(function (r) {
|
|
395
|
+
if (_this._isCanceled) {
|
|
396
|
+
reject_1(r);
|
|
247
397
|
}
|
|
248
398
|
else {
|
|
249
399
|
if (onfulfilled) {
|
|
@@ -253,20 +403,20 @@ class CancelablePromise$1 {
|
|
|
253
403
|
resolve(r);
|
|
254
404
|
}
|
|
255
405
|
}
|
|
256
|
-
},
|
|
406
|
+
}, reject_1);
|
|
257
407
|
}
|
|
258
408
|
});
|
|
259
409
|
p._parentPromise = this;
|
|
260
410
|
this._children.push(p);
|
|
261
411
|
return p;
|
|
262
|
-
}
|
|
263
|
-
catch(onrejected) {
|
|
412
|
+
};
|
|
413
|
+
CancelablePromise.prototype.catch = function (onrejected) {
|
|
264
414
|
if (this._isCanceled && onrejected) {
|
|
265
415
|
onrejected(new CancelError());
|
|
266
416
|
}
|
|
267
417
|
return this.then(undefined, onrejected);
|
|
268
|
-
}
|
|
269
|
-
finally(onfinally) {
|
|
418
|
+
};
|
|
419
|
+
CancelablePromise.prototype.finally = function (onfinally) {
|
|
270
420
|
if (this._promise) {
|
|
271
421
|
return this._promise.finally(onfinally);
|
|
272
422
|
}
|
|
@@ -274,24 +424,25 @@ class CancelablePromise$1 {
|
|
|
274
424
|
return Promise.reject(new CancelError());
|
|
275
425
|
}
|
|
276
426
|
return Promise.reject(onfinally);
|
|
277
|
-
}
|
|
278
|
-
cancel() {
|
|
427
|
+
};
|
|
428
|
+
CancelablePromise.prototype.cancel = function () {
|
|
279
429
|
// No reason to run cancel action if promise is already complete
|
|
280
430
|
if (this._isCanceled || !this._isPending) {
|
|
281
431
|
return this;
|
|
282
432
|
}
|
|
283
433
|
this._isCanceled = true;
|
|
284
|
-
|
|
434
|
+
var parent = this._getTopParent();
|
|
285
435
|
if (parent) {
|
|
286
436
|
parent.cancel();
|
|
287
437
|
}
|
|
288
438
|
if (this._children) {
|
|
289
|
-
this._children.forEach((x)
|
|
439
|
+
this._children.forEach(function (x) { return x.cancel(); });
|
|
290
440
|
}
|
|
291
441
|
if (this._isPending) {
|
|
292
442
|
if (this._cancelHandlers.length) {
|
|
293
443
|
try {
|
|
294
|
-
for (
|
|
444
|
+
for (var _i = 0, _a = this._cancelHandlers; _i < _a.length; _i++) {
|
|
445
|
+
var handler = _a[_i];
|
|
295
446
|
handler();
|
|
296
447
|
}
|
|
297
448
|
}
|
|
@@ -305,10 +456,10 @@ class CancelablePromise$1 {
|
|
|
305
456
|
}
|
|
306
457
|
this._destroy();
|
|
307
458
|
return this;
|
|
308
|
-
}
|
|
309
|
-
_getTopParent() {
|
|
310
|
-
|
|
311
|
-
|
|
459
|
+
};
|
|
460
|
+
CancelablePromise.prototype._getTopParent = function () {
|
|
461
|
+
var parent = this._parentPromise;
|
|
462
|
+
var hasParent = !!parent;
|
|
312
463
|
while (hasParent) {
|
|
313
464
|
if (parent && parent._parentPromise) {
|
|
314
465
|
parent = parent._parentPromise;
|
|
@@ -319,16 +470,17 @@ class CancelablePromise$1 {
|
|
|
319
470
|
}
|
|
320
471
|
}
|
|
321
472
|
return parent;
|
|
322
|
-
}
|
|
323
|
-
_destroy() {
|
|
473
|
+
};
|
|
474
|
+
CancelablePromise.prototype._destroy = function () {
|
|
324
475
|
this._setCanceledCallback = undefined;
|
|
325
476
|
this._cancelPromise = undefined;
|
|
326
477
|
this._promise = undefined;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
CancelablePromise
|
|
330
|
-
CancelablePromise
|
|
331
|
-
CancelablePromise
|
|
478
|
+
};
|
|
479
|
+
CancelablePromise.CancelError = CancelError;
|
|
480
|
+
CancelablePromise.TimeoutError = TimeoutError;
|
|
481
|
+
CancelablePromise.PromiseControl = PromiseControl;
|
|
482
|
+
return CancelablePromise;
|
|
483
|
+
}());
|
|
332
484
|
Object.setPrototypeOf(CancelablePromise$1.prototype, Promise.prototype);
|
|
333
485
|
|
|
334
486
|
/**
|
|
@@ -381,9 +533,15 @@ function full(val) {
|
|
|
381
533
|
* @param target - The target object to copy to.
|
|
382
534
|
* @param sources - One or more source objects from which to copy properties
|
|
383
535
|
*/
|
|
384
|
-
function objectAssign(target
|
|
385
|
-
|
|
386
|
-
|
|
536
|
+
function objectAssign(target) {
|
|
537
|
+
var sources = [];
|
|
538
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
539
|
+
sources[_i - 1] = arguments[_i];
|
|
540
|
+
}
|
|
541
|
+
for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) {
|
|
542
|
+
var source = sources_1[_a];
|
|
543
|
+
for (var _b = 0, _c = Object.getOwnPropertyNames(source); _b < _c.length; _b++) {
|
|
544
|
+
var prop = _c[_b];
|
|
387
545
|
target[prop] = source[prop];
|
|
388
546
|
}
|
|
389
547
|
}
|
|
@@ -421,15 +579,15 @@ function isEqual(a, b, o, p) {
|
|
|
421
579
|
}
|
|
422
580
|
// based on https://stackoverflow.com/a/13143059
|
|
423
581
|
function objectDeepEqual(o, p) {
|
|
424
|
-
|
|
425
|
-
|
|
582
|
+
var keysO = Object.keys(o).sort();
|
|
583
|
+
var keysP = Object.keys(p).sort();
|
|
426
584
|
if (keysO.length !== keysP.length)
|
|
427
585
|
return false;
|
|
428
586
|
if (keysO.join('') !== keysP.join(''))
|
|
429
587
|
return false;
|
|
430
|
-
for (
|
|
431
|
-
|
|
432
|
-
|
|
588
|
+
for (var i = 0; i < keysO.length; i++) {
|
|
589
|
+
var oVal = o[keysO[i]];
|
|
590
|
+
var pVal = p[keysP[i]];
|
|
433
591
|
if (!isEqual(oVal, pVal, o, p)) {
|
|
434
592
|
return false;
|
|
435
593
|
}
|
|
@@ -438,8 +596,8 @@ function objectDeepEqual(o, p) {
|
|
|
438
596
|
}
|
|
439
597
|
|
|
440
598
|
function objectRemoveEmpty(obj) {
|
|
441
|
-
|
|
442
|
-
Object.keys(obj).forEach((key)
|
|
599
|
+
var newObj = {};
|
|
600
|
+
Object.keys(obj).forEach(function (key) {
|
|
443
601
|
if (!(obj[key] instanceof Array) && obj[key] === Object(obj[key])) {
|
|
444
602
|
newObj[key] = objectRemoveEmpty(obj[key]);
|
|
445
603
|
}
|
|
@@ -455,53 +613,109 @@ function fixUrlStr(url) {
|
|
|
455
613
|
return url.replace(/([^:]\/)\/+/g, '$1');
|
|
456
614
|
}
|
|
457
615
|
|
|
458
|
-
|
|
459
|
-
|
|
616
|
+
var BaseGeocoder = /** @class */ (function () {
|
|
617
|
+
function BaseGeocoder(options) {
|
|
460
618
|
if (options) {
|
|
461
619
|
objectAssign(this, options);
|
|
462
620
|
}
|
|
463
621
|
}
|
|
464
|
-
|
|
622
|
+
return BaseGeocoder;
|
|
623
|
+
}());
|
|
465
624
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
625
|
+
var ID$1 = 0;
|
|
626
|
+
var Geocoder = /** @class */ (function (_super) {
|
|
627
|
+
__extends(Geocoder, _super);
|
|
628
|
+
function Geocoder(options) {
|
|
629
|
+
var _this = _super.call(this, options) || this;
|
|
630
|
+
_this.providers = [];
|
|
471
631
|
if (options && options.providers) {
|
|
472
|
-
|
|
632
|
+
_this.providers = options.providers;
|
|
473
633
|
}
|
|
634
|
+
return _this;
|
|
474
635
|
}
|
|
475
|
-
abort() {
|
|
476
|
-
this.providers.forEach((x)
|
|
636
|
+
Geocoder.prototype.abort = function () {
|
|
637
|
+
this.providers.forEach(function (x) {
|
|
477
638
|
if (x.abort) {
|
|
478
639
|
x.abort();
|
|
479
640
|
}
|
|
480
641
|
});
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
642
|
+
};
|
|
643
|
+
Geocoder.prototype.search = function (query) {
|
|
644
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
645
|
+
var _i, _a, provider, results, results_1, results_1_1, r, e_1_1;
|
|
646
|
+
var e_1, _b;
|
|
647
|
+
return __generator(this, function (_c) {
|
|
648
|
+
switch (_c.label) {
|
|
649
|
+
case 0:
|
|
650
|
+
_i = 0, _a = this.providers;
|
|
651
|
+
_c.label = 1;
|
|
652
|
+
case 1:
|
|
653
|
+
if (!(_i < _a.length)) return [3 /*break*/, 19];
|
|
654
|
+
provider = _a[_i];
|
|
655
|
+
_c.label = 2;
|
|
656
|
+
case 2:
|
|
657
|
+
_c.trys.push([2, 17, , 18]);
|
|
658
|
+
results = provider.search(query);
|
|
659
|
+
_c.label = 3;
|
|
660
|
+
case 3:
|
|
661
|
+
_c.trys.push([3, 10, 11, 16]);
|
|
662
|
+
results_1 = (e_1 = void 0, __asyncValues(results));
|
|
663
|
+
_c.label = 4;
|
|
664
|
+
case 4: return [4 /*yield*/, __await(results_1.next())];
|
|
665
|
+
case 5:
|
|
666
|
+
if (!(results_1_1 = _c.sent(), !results_1_1.done)) return [3 /*break*/, 9];
|
|
667
|
+
r = results_1_1.value;
|
|
668
|
+
return [4 /*yield*/, __await(__assign(__assign({}, r), { provider: provider, _id: ID$1++ }))];
|
|
669
|
+
case 6: return [4 /*yield*/, _c.sent()];
|
|
670
|
+
case 7:
|
|
671
|
+
_c.sent();
|
|
672
|
+
_c.label = 8;
|
|
673
|
+
case 8: return [3 /*break*/, 4];
|
|
674
|
+
case 9: return [3 /*break*/, 16];
|
|
675
|
+
case 10:
|
|
676
|
+
e_1_1 = _c.sent();
|
|
677
|
+
e_1 = { error: e_1_1 };
|
|
678
|
+
return [3 /*break*/, 16];
|
|
679
|
+
case 11:
|
|
680
|
+
_c.trys.push([11, , 14, 15]);
|
|
681
|
+
if (!(results_1_1 && !results_1_1.done && (_b = results_1.return))) return [3 /*break*/, 13];
|
|
682
|
+
return [4 /*yield*/, __await(_b.call(results_1))];
|
|
683
|
+
case 12:
|
|
684
|
+
_c.sent();
|
|
685
|
+
_c.label = 13;
|
|
686
|
+
case 13: return [3 /*break*/, 15];
|
|
687
|
+
case 14:
|
|
688
|
+
if (e_1) throw e_1.error;
|
|
689
|
+
return [7 /*endfinally*/];
|
|
690
|
+
case 15: return [7 /*endfinally*/];
|
|
691
|
+
case 16: return [3 /*break*/, 18];
|
|
692
|
+
case 17:
|
|
693
|
+
_c.sent();
|
|
694
|
+
return [3 /*break*/, 18];
|
|
695
|
+
case 18:
|
|
696
|
+
_i++;
|
|
697
|
+
return [3 /*break*/, 1];
|
|
698
|
+
case 19: return [2 /*return*/];
|
|
488
699
|
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
result(item) {
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
Geocoder.prototype.result = function (item) {
|
|
496
704
|
if (item.provider) {
|
|
497
705
|
return item.provider.result(item);
|
|
498
706
|
}
|
|
499
707
|
return CancelablePromise.resolve(undefined);
|
|
500
|
-
}
|
|
501
|
-
|
|
708
|
+
};
|
|
709
|
+
return Geocoder;
|
|
710
|
+
}(BaseGeocoder));
|
|
502
711
|
|
|
503
|
-
|
|
504
|
-
|
|
712
|
+
var BaseProvider = /** @class */ (function (_super) {
|
|
713
|
+
__extends(BaseProvider, _super);
|
|
714
|
+
function BaseProvider() {
|
|
715
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
716
|
+
}
|
|
717
|
+
return BaseProvider;
|
|
718
|
+
}(BaseGeocoder));
|
|
505
719
|
|
|
506
720
|
var events = {exports: {}};
|
|
507
721
|
|
|
@@ -1009,23 +1223,24 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
|
1009
1223
|
* console.log(COUNTER); // 1
|
|
1010
1224
|
* ```
|
|
1011
1225
|
*/
|
|
1012
|
-
|
|
1013
|
-
|
|
1226
|
+
var Cache$1 = /** @class */ (function () {
|
|
1227
|
+
function Cache(options) {
|
|
1228
|
+
if (options === void 0) { options = {}; }
|
|
1014
1229
|
var _a;
|
|
1015
1230
|
this.cache = [];
|
|
1016
|
-
|
|
1017
|
-
if (Cache
|
|
1018
|
-
return Cache
|
|
1231
|
+
var namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
|
|
1232
|
+
if (Cache.instance[namespace]) {
|
|
1233
|
+
return Cache.instance[namespace];
|
|
1019
1234
|
}
|
|
1020
|
-
Cache
|
|
1235
|
+
Cache.instance[namespace] = this;
|
|
1021
1236
|
return this;
|
|
1022
1237
|
}
|
|
1023
|
-
clean() {
|
|
1238
|
+
Cache.prototype.clean = function () {
|
|
1024
1239
|
this.cache.length = 0;
|
|
1025
|
-
}
|
|
1026
|
-
all() {
|
|
1240
|
+
};
|
|
1241
|
+
Cache.prototype.all = function () {
|
|
1027
1242
|
return this.cache;
|
|
1028
|
-
}
|
|
1243
|
+
};
|
|
1029
1244
|
/**
|
|
1030
1245
|
* Caching only a non-empty value.
|
|
1031
1246
|
*
|
|
@@ -1048,23 +1263,24 @@ class Cache$1 {
|
|
|
1048
1263
|
*
|
|
1049
1264
|
* ```
|
|
1050
1265
|
*/
|
|
1051
|
-
addFull(key, valueToSet, props) {
|
|
1266
|
+
Cache.prototype.addFull = function (key, valueToSet, props) {
|
|
1052
1267
|
return this.add(key, valueToSet, props, true);
|
|
1053
|
-
}
|
|
1054
|
-
add(key, valueToSet, props, onlyFull) {
|
|
1055
|
-
|
|
1268
|
+
};
|
|
1269
|
+
Cache.prototype.add = function (key, valueToSet, props, onlyFull) {
|
|
1270
|
+
var _this = this;
|
|
1271
|
+
var exist = this._find(key, props);
|
|
1056
1272
|
if (!exist) {
|
|
1057
|
-
|
|
1273
|
+
var value = void 0;
|
|
1058
1274
|
if (valueToSet instanceof Function) {
|
|
1059
1275
|
value = valueToSet();
|
|
1060
1276
|
}
|
|
1061
1277
|
else {
|
|
1062
1278
|
value = valueToSet;
|
|
1063
1279
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
key,
|
|
1067
|
-
value,
|
|
1280
|
+
var props_ = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
1281
|
+
var cacheItem = {
|
|
1282
|
+
key: key,
|
|
1283
|
+
value: value,
|
|
1068
1284
|
props: props_,
|
|
1069
1285
|
// TODO: remove backward compatibility use only props
|
|
1070
1286
|
options: props_,
|
|
@@ -1074,14 +1290,14 @@ class Cache$1 {
|
|
|
1074
1290
|
}
|
|
1075
1291
|
this.cache.push(cacheItem);
|
|
1076
1292
|
if (value instanceof Promise) {
|
|
1077
|
-
value.catch((er)
|
|
1078
|
-
|
|
1293
|
+
value.catch(function (er) {
|
|
1294
|
+
_this.delete(key, props);
|
|
1079
1295
|
throw er;
|
|
1080
1296
|
});
|
|
1081
1297
|
if (onlyFull) {
|
|
1082
|
-
value.then((x)
|
|
1298
|
+
value.then(function (x) {
|
|
1083
1299
|
if (!full(x)) {
|
|
1084
|
-
|
|
1300
|
+
_this.delete(key, props);
|
|
1085
1301
|
}
|
|
1086
1302
|
return x;
|
|
1087
1303
|
});
|
|
@@ -1093,50 +1309,55 @@ class Cache$1 {
|
|
|
1093
1309
|
else {
|
|
1094
1310
|
return exist.value;
|
|
1095
1311
|
}
|
|
1096
|
-
}
|
|
1097
|
-
match(key, props) {
|
|
1098
|
-
|
|
1312
|
+
};
|
|
1313
|
+
Cache.prototype.match = function (key, props) {
|
|
1314
|
+
var cacheRecord = this._find(key, props);
|
|
1099
1315
|
if (cacheRecord) {
|
|
1100
1316
|
return cacheRecord.value;
|
|
1101
1317
|
}
|
|
1102
|
-
}
|
|
1103
|
-
matchAll(key, props) {
|
|
1318
|
+
};
|
|
1319
|
+
Cache.prototype.matchAll = function (key, props) {
|
|
1320
|
+
var _this = this;
|
|
1104
1321
|
if (key) {
|
|
1105
1322
|
return this.cache
|
|
1106
|
-
.filter((x)
|
|
1107
|
-
.map((x)
|
|
1323
|
+
.filter(function (x) { return _this._filter(x, key, props); })
|
|
1324
|
+
.map(function (x) { return x.value; });
|
|
1108
1325
|
}
|
|
1109
|
-
return this.cache.map((x)
|
|
1110
|
-
}
|
|
1111
|
-
delete(keyOrItem, props) {
|
|
1112
|
-
|
|
1326
|
+
return this.cache.map(function (x) { return x.value; });
|
|
1327
|
+
};
|
|
1328
|
+
Cache.prototype.delete = function (keyOrItem, props) {
|
|
1329
|
+
var _this = this;
|
|
1330
|
+
var exist = [];
|
|
1113
1331
|
if (typeof keyOrItem === 'string') {
|
|
1114
|
-
exist = this.cache.filter((x)
|
|
1332
|
+
exist = this.cache.filter(function (x) { return _this._filter(x, keyOrItem, props); });
|
|
1115
1333
|
}
|
|
1116
1334
|
else {
|
|
1117
1335
|
exist.push(keyOrItem);
|
|
1118
1336
|
}
|
|
1119
|
-
for (
|
|
1120
|
-
|
|
1337
|
+
for (var _i = 0, exist_1 = exist; _i < exist_1.length; _i++) {
|
|
1338
|
+
var e = exist_1[_i];
|
|
1339
|
+
var index = this.cache.indexOf(e);
|
|
1121
1340
|
this.cache.splice(index, 1);
|
|
1122
1341
|
}
|
|
1123
|
-
}
|
|
1124
|
-
_find(key, props) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1342
|
+
};
|
|
1343
|
+
Cache.prototype._find = function (key, props) {
|
|
1344
|
+
var _this = this;
|
|
1345
|
+
return this.cache.find(function (x) { return _this._filter(x, key, props); });
|
|
1346
|
+
};
|
|
1347
|
+
Cache.prototype._filter = function (item, key, props) {
|
|
1128
1348
|
if (item.key === key) {
|
|
1129
1349
|
if (props) {
|
|
1130
1350
|
// TODO: remove backward compatibility
|
|
1131
|
-
|
|
1351
|
+
var itemProps = item.props || item.options;
|
|
1132
1352
|
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
1133
1353
|
}
|
|
1134
1354
|
return true;
|
|
1135
1355
|
}
|
|
1136
1356
|
return false;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
Cache
|
|
1357
|
+
};
|
|
1358
|
+
Cache.instance = {};
|
|
1359
|
+
return Cache;
|
|
1360
|
+
}());
|
|
1140
1361
|
|
|
1141
1362
|
/**
|
|
1142
1363
|
* Caching for asynchronous functions
|
|
@@ -1149,43 +1370,49 @@ var Cache = Cache$1;
|
|
|
1149
1370
|
/**
|
|
1150
1371
|
* Thrown when...
|
|
1151
1372
|
*/
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
Object.
|
|
1158
|
-
|
|
1159
|
-
|
|
1373
|
+
var NgwError = /** @class */ (function (_super) {
|
|
1374
|
+
__extends(NgwError, _super);
|
|
1375
|
+
function NgwError(er) {
|
|
1376
|
+
var _this = _super.call(this) || this;
|
|
1377
|
+
_this.name = 'NgwError';
|
|
1378
|
+
Object.assign(_this, er);
|
|
1379
|
+
Object.setPrototypeOf(_this, NgwError.prototype);
|
|
1380
|
+
return _this;
|
|
1381
|
+
}
|
|
1382
|
+
return NgwError;
|
|
1383
|
+
}(Error));
|
|
1160
1384
|
|
|
1161
1385
|
/**
|
|
1162
1386
|
* Thrown when...
|
|
1163
1387
|
*/
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
Possibly invalid NGW URL entered or CORS not configured to get request from
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1388
|
+
var NetworkError = /** @class */ (function (_super) {
|
|
1389
|
+
__extends(NetworkError, _super);
|
|
1390
|
+
function NetworkError(url) {
|
|
1391
|
+
var _this = _super.call(this) || this;
|
|
1392
|
+
_this.name = 'NetworkError';
|
|
1393
|
+
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
1394
|
+
_this.message = "Unable to request ".concat(url, ".\n Possibly invalid NGW URL entered or CORS not configured to get request from ").concat(location.origin); // /control-panel/cors
|
|
1395
|
+
return _this;
|
|
1396
|
+
}
|
|
1397
|
+
return NetworkError;
|
|
1398
|
+
}(Error));
|
|
1173
1399
|
|
|
1174
1400
|
function isObject(val) {
|
|
1175
1401
|
return Object.prototype.toString.call(val) === '[object Object]';
|
|
1176
1402
|
}
|
|
1177
1403
|
|
|
1178
|
-
|
|
1404
|
+
var loadData;
|
|
1179
1405
|
// @ts-ignore
|
|
1180
1406
|
{
|
|
1181
|
-
loadData = (url, callback, options
|
|
1407
|
+
loadData = function (url, callback, options, error, onCancel) {
|
|
1408
|
+
if (options === void 0) { options = {}; }
|
|
1182
1409
|
options.method = options.method || 'GET';
|
|
1183
|
-
|
|
1410
|
+
var xhr = new XMLHttpRequest();
|
|
1184
1411
|
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
1185
1412
|
if (options.responseType === 'blob') {
|
|
1186
1413
|
xhr.responseType = options.responseType;
|
|
1187
1414
|
}
|
|
1188
|
-
|
|
1415
|
+
var getResponseText = function () {
|
|
1189
1416
|
try {
|
|
1190
1417
|
return JSON.parse(xhr.responseText);
|
|
1191
1418
|
}
|
|
@@ -1193,8 +1420,9 @@ let loadData;
|
|
|
1193
1420
|
return xhr.responseText;
|
|
1194
1421
|
}
|
|
1195
1422
|
};
|
|
1196
|
-
|
|
1197
|
-
|
|
1423
|
+
var processingResponse = function (forError) {
|
|
1424
|
+
if (forError === void 0) { forError = false; }
|
|
1425
|
+
var cb = forError ? error : callback;
|
|
1198
1426
|
if (options.responseType === 'blob') {
|
|
1199
1427
|
cb(xhr.response);
|
|
1200
1428
|
}
|
|
@@ -1207,7 +1435,7 @@ let loadData;
|
|
|
1207
1435
|
}
|
|
1208
1436
|
}
|
|
1209
1437
|
};
|
|
1210
|
-
xhr.onload = ()
|
|
1438
|
+
xhr.onload = function () {
|
|
1211
1439
|
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
1212
1440
|
error(new NgwError(getResponseText()));
|
|
1213
1441
|
}
|
|
@@ -1229,7 +1457,7 @@ let loadData;
|
|
|
1229
1457
|
// error('request error');
|
|
1230
1458
|
// }
|
|
1231
1459
|
// };
|
|
1232
|
-
xhr.onerror = (er)
|
|
1460
|
+
xhr.onerror = function (er) {
|
|
1233
1461
|
if (xhr.status === 0) {
|
|
1234
1462
|
error(new NetworkError(url));
|
|
1235
1463
|
}
|
|
@@ -1239,17 +1467,17 @@ let loadData;
|
|
|
1239
1467
|
};
|
|
1240
1468
|
xhr.upload.onprogress = function (e) {
|
|
1241
1469
|
if (e.lengthComputable) {
|
|
1242
|
-
|
|
1470
|
+
var percentComplete = (e.loaded / e.total) * 100;
|
|
1243
1471
|
if (options.onProgress) {
|
|
1244
1472
|
options.onProgress(percentComplete, e);
|
|
1245
1473
|
}
|
|
1246
1474
|
// console.log(percentComplete + '% uploaded');
|
|
1247
1475
|
}
|
|
1248
1476
|
};
|
|
1249
|
-
|
|
1477
|
+
var headers = options.headers;
|
|
1250
1478
|
if (headers) {
|
|
1251
|
-
for (
|
|
1252
|
-
|
|
1479
|
+
for (var h in headers) {
|
|
1480
|
+
var header = headers[h];
|
|
1253
1481
|
if (typeof header === 'string') {
|
|
1254
1482
|
xhr.setRequestHeader(h, header);
|
|
1255
1483
|
}
|
|
@@ -1258,12 +1486,12 @@ let loadData;
|
|
|
1258
1486
|
if (options.withCredentials !== undefined) {
|
|
1259
1487
|
xhr.withCredentials = options.withCredentials;
|
|
1260
1488
|
}
|
|
1261
|
-
|
|
1489
|
+
var data;
|
|
1262
1490
|
if (options.file) {
|
|
1263
1491
|
data = new FormData();
|
|
1264
1492
|
data.append('file', options.file);
|
|
1265
1493
|
if (options.data) {
|
|
1266
|
-
for (
|
|
1494
|
+
for (var d in options.data) {
|
|
1267
1495
|
data.append(d, data[d]);
|
|
1268
1496
|
}
|
|
1269
1497
|
}
|
|
@@ -1276,7 +1504,12 @@ let loadData;
|
|
|
1276
1504
|
: null;
|
|
1277
1505
|
}
|
|
1278
1506
|
if (onCancel) {
|
|
1279
|
-
onCancel(()
|
|
1507
|
+
onCancel(function () {
|
|
1508
|
+
xhr.abort();
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
if (options.signal) {
|
|
1512
|
+
options.signal.addEventListener('abort', function () {
|
|
1280
1513
|
xhr.abort();
|
|
1281
1514
|
});
|
|
1282
1515
|
}
|
|
@@ -1285,10 +1518,10 @@ let loadData;
|
|
|
1285
1518
|
}
|
|
1286
1519
|
|
|
1287
1520
|
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
1288
|
-
|
|
1521
|
+
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
1289
1522
|
function template(str, data) {
|
|
1290
|
-
return str.replace(templateRe, (s, key)
|
|
1291
|
-
|
|
1523
|
+
return str.replace(templateRe, function (s, key) {
|
|
1524
|
+
var value = data[key];
|
|
1292
1525
|
if (value === undefined) {
|
|
1293
1526
|
throw new Error('No value provided for letiable ' + s);
|
|
1294
1527
|
}
|
|
@@ -1302,33 +1535,39 @@ function template(str, data) {
|
|
|
1302
1535
|
/**
|
|
1303
1536
|
* Thrown when ...
|
|
1304
1537
|
*/
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1538
|
+
var ResourceNotFoundError = /** @class */ (function (_super) {
|
|
1539
|
+
__extends(ResourceNotFoundError, _super);
|
|
1540
|
+
function ResourceNotFoundError(obj) {
|
|
1541
|
+
var _this = _super.call(this, obj) || this;
|
|
1542
|
+
_this.name = 'ResourceNotFoundError';
|
|
1543
|
+
_this.exception = 'nextgisweb.resource.exception.ResourceNotFound';
|
|
1544
|
+
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
1545
|
+
return _this;
|
|
1546
|
+
}
|
|
1547
|
+
return ResourceNotFoundError;
|
|
1548
|
+
}(NgwError));
|
|
1313
1549
|
|
|
1314
1550
|
/**
|
|
1315
1551
|
* Thrown when ...
|
|
1316
1552
|
*/
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1553
|
+
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
1554
|
+
__extends(InsufficientPermissionsError, _super);
|
|
1555
|
+
function InsufficientPermissionsError(obj) {
|
|
1556
|
+
var _this = _super.call(this, obj) || this;
|
|
1557
|
+
_this.name = 'InsufficientPermissionsError';
|
|
1558
|
+
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
1559
|
+
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
1560
|
+
return _this;
|
|
1561
|
+
}
|
|
1562
|
+
return InsufficientPermissionsError;
|
|
1563
|
+
}(NgwError));
|
|
1564
|
+
|
|
1565
|
+
var CONNECTORS = [];
|
|
1327
1566
|
function addConnector(connector) {
|
|
1328
1567
|
CONNECTORS.push(connector);
|
|
1329
1568
|
}
|
|
1330
1569
|
function findConnector(options) {
|
|
1331
|
-
return CONNECTORS.find((x)
|
|
1570
|
+
return CONNECTORS.find(function (x) {
|
|
1332
1571
|
if (x.options.baseUrl === options.baseUrl) {
|
|
1333
1572
|
if (options.auth) {
|
|
1334
1573
|
if (x.options.auth) {
|
|
@@ -1343,13 +1582,13 @@ function findConnector(options) {
|
|
|
1343
1582
|
});
|
|
1344
1583
|
}
|
|
1345
1584
|
function removeConnector(connector) {
|
|
1346
|
-
|
|
1585
|
+
var index = CONNECTORS.indexOf(connector);
|
|
1347
1586
|
if (index !== -1) {
|
|
1348
1587
|
CONNECTORS.splice(index, 1);
|
|
1349
1588
|
}
|
|
1350
1589
|
}
|
|
1351
1590
|
|
|
1352
|
-
|
|
1591
|
+
var exclude = ['description'];
|
|
1353
1592
|
/**
|
|
1354
1593
|
* @remarks
|
|
1355
1594
|
* https://docs.nextgis.ru/docs_ngweb_dev/doc/developer/resource.html#search-resources
|
|
@@ -1360,14 +1599,16 @@ const exclude = ['description'];
|
|
|
1360
1599
|
*
|
|
1361
1600
|
* @param resource - Any property from NGW resource item
|
|
1362
1601
|
*/
|
|
1363
|
-
function resourceToQuery(resource, prefix
|
|
1602
|
+
function resourceToQuery(resource, prefix) {
|
|
1603
|
+
if (prefix === void 0) { prefix = ''; }
|
|
1364
1604
|
prefix = prefix ? prefix + '__' : '';
|
|
1365
|
-
|
|
1366
|
-
for (
|
|
1605
|
+
var query = {};
|
|
1606
|
+
for (var _i = 0, _a = Object.entries(resource); _i < _a.length; _i++) {
|
|
1607
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
1367
1608
|
if (exclude.indexOf(key) === -1) {
|
|
1368
1609
|
if (isObject(value)) {
|
|
1369
1610
|
if (key === 'owner_user') {
|
|
1370
|
-
|
|
1611
|
+
var children = resourceToQuery(value, key);
|
|
1371
1612
|
Object.assign(query, children);
|
|
1372
1613
|
}
|
|
1373
1614
|
else if (key === 'parent' && 'id' in value) {
|
|
@@ -1386,8 +1627,8 @@ function resourceCompare(res1, res2) {
|
|
|
1386
1627
|
return objectDeepEqual(res1, res2);
|
|
1387
1628
|
}
|
|
1388
1629
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1630
|
+
var ResourcesControl = /** @class */ (function () {
|
|
1631
|
+
function ResourcesControl(connector) {
|
|
1391
1632
|
this.connector = connector;
|
|
1392
1633
|
this.cache = new Cache();
|
|
1393
1634
|
}
|
|
@@ -1401,10 +1642,11 @@ class ResourcesControl {
|
|
|
1401
1642
|
* @remarks
|
|
1402
1643
|
* Fetching resource would be cached to speed up next call
|
|
1403
1644
|
*/
|
|
1404
|
-
getOne(resource, requestOptions) {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1645
|
+
ResourcesControl.prototype.getOne = function (resource, requestOptions) {
|
|
1646
|
+
var _this = this;
|
|
1647
|
+
var cache = new Cache();
|
|
1648
|
+
var forCache = {};
|
|
1649
|
+
var opt = __assign(__assign({}, requestOptions), { cache: false });
|
|
1408
1650
|
if (typeof resource === 'string') {
|
|
1409
1651
|
forCache.keyname = resource;
|
|
1410
1652
|
}
|
|
@@ -1412,30 +1654,35 @@ class ResourcesControl {
|
|
|
1412
1654
|
forCache.id = resource;
|
|
1413
1655
|
}
|
|
1414
1656
|
else if (isObject(resource)) {
|
|
1415
|
-
|
|
1657
|
+
if (resource.id !== undefined) {
|
|
1658
|
+
forCache.id = resource.id;
|
|
1659
|
+
}
|
|
1660
|
+
else if (resource.keyname) {
|
|
1661
|
+
forCache.keyname = resource.keyname;
|
|
1662
|
+
}
|
|
1416
1663
|
}
|
|
1417
|
-
|
|
1664
|
+
var makeRequest = function () {
|
|
1418
1665
|
if (typeof resource === 'string') {
|
|
1419
|
-
return
|
|
1666
|
+
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
1420
1667
|
}
|
|
1421
1668
|
else if (typeof resource === 'number') {
|
|
1422
|
-
return
|
|
1669
|
+
return _this._fetchResourceById(resource, opt);
|
|
1423
1670
|
}
|
|
1424
1671
|
else if (isObject(resource)) {
|
|
1425
|
-
return
|
|
1672
|
+
return _this._fetchResourceBy(resource, opt);
|
|
1426
1673
|
}
|
|
1427
1674
|
return CancelablePromise.resolve(undefined);
|
|
1428
1675
|
};
|
|
1429
1676
|
return cache.addFull('resource', makeRequest, forCache);
|
|
1430
|
-
}
|
|
1431
|
-
getOneOrFail(resource, requestOptions) {
|
|
1432
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
1677
|
+
};
|
|
1678
|
+
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
1679
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1433
1680
|
if (res) {
|
|
1434
1681
|
return res;
|
|
1435
1682
|
}
|
|
1436
1683
|
throw new ResourceNotFoundError();
|
|
1437
1684
|
});
|
|
1438
|
-
}
|
|
1685
|
+
};
|
|
1439
1686
|
/**
|
|
1440
1687
|
* A fast way to retrieve resource ID for any resource definition.
|
|
1441
1688
|
* @param resource - Any available resource definition
|
|
@@ -1446,19 +1693,19 @@ class ResourcesControl {
|
|
|
1446
1693
|
* then this method will come in handy to facilitate the extraction of the identifier
|
|
1447
1694
|
* if the resource is specified through a keyname or other parameters.
|
|
1448
1695
|
*/
|
|
1449
|
-
getId(resource, requestOptions) {
|
|
1696
|
+
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
1450
1697
|
if (typeof resource === 'number') {
|
|
1451
1698
|
return CancelablePromise.resolve(resource);
|
|
1452
1699
|
}
|
|
1453
1700
|
else if (typeof resource === 'string' || isObject(resource)) {
|
|
1454
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
1701
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
1455
1702
|
if (res) {
|
|
1456
1703
|
return res.resource.id;
|
|
1457
1704
|
}
|
|
1458
1705
|
});
|
|
1459
1706
|
}
|
|
1460
1707
|
return CancelablePromise.resolve(undefined);
|
|
1461
|
-
}
|
|
1708
|
+
};
|
|
1462
1709
|
/**
|
|
1463
1710
|
* A fast way to retrieve resource ID for any resource definition.
|
|
1464
1711
|
* @param resource - Any available resource definition
|
|
@@ -1467,33 +1714,32 @@ class ResourcesControl {
|
|
|
1467
1714
|
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
1468
1715
|
* To not make one more checks if the resource is definitely exists
|
|
1469
1716
|
*/
|
|
1470
|
-
getIdOrFail(resource, requestOptions) {
|
|
1471
|
-
return this.getId(resource, requestOptions).then((resp)
|
|
1717
|
+
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
1718
|
+
return this.getId(resource, requestOptions).then(function (resp) {
|
|
1472
1719
|
if (resp === undefined) {
|
|
1473
1720
|
throw new Error();
|
|
1474
1721
|
}
|
|
1475
1722
|
return resp;
|
|
1476
1723
|
});
|
|
1477
|
-
}
|
|
1478
|
-
getMany(resource, requestOptions) {
|
|
1479
|
-
|
|
1724
|
+
};
|
|
1725
|
+
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
1726
|
+
var _this = this;
|
|
1727
|
+
return this._resourceCacheFilter(resource).then(function (items) {
|
|
1480
1728
|
if (!items.length) {
|
|
1481
|
-
|
|
1729
|
+
var query = {};
|
|
1482
1730
|
if (resource.keyname) {
|
|
1483
1731
|
query.keyname = resource.keyname;
|
|
1484
1732
|
}
|
|
1485
1733
|
else {
|
|
1486
1734
|
Object.assign(query, resourceToQuery(resource));
|
|
1487
1735
|
}
|
|
1488
|
-
return
|
|
1489
|
-
.get('resource.search', requestOptions, {
|
|
1490
|
-
|
|
1491
|
-
...query,
|
|
1492
|
-
})
|
|
1493
|
-
.then((resources) => {
|
|
1736
|
+
return _this.connector
|
|
1737
|
+
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
1738
|
+
.then(function (resources) {
|
|
1494
1739
|
if (resources) {
|
|
1495
|
-
for (
|
|
1496
|
-
|
|
1740
|
+
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
1741
|
+
var x = resources_1[_i];
|
|
1742
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(x), {
|
|
1497
1743
|
id: x.resource.id,
|
|
1498
1744
|
});
|
|
1499
1745
|
}
|
|
@@ -1503,97 +1749,137 @@ class ResourcesControl {
|
|
|
1503
1749
|
}
|
|
1504
1750
|
return items;
|
|
1505
1751
|
});
|
|
1506
|
-
}
|
|
1507
|
-
getParent(resource, requestOptions) {
|
|
1508
|
-
|
|
1752
|
+
};
|
|
1753
|
+
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
1754
|
+
var _this = this;
|
|
1755
|
+
return this.getOne(resource, requestOptions).then(function (child) {
|
|
1509
1756
|
if (child) {
|
|
1510
|
-
return
|
|
1757
|
+
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
1511
1758
|
}
|
|
1512
1759
|
return CancelablePromise.resolve(undefined);
|
|
1513
1760
|
});
|
|
1514
|
-
}
|
|
1515
|
-
getChildrenOf(resource, requestOptions) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1761
|
+
};
|
|
1762
|
+
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
1763
|
+
var _this = this;
|
|
1764
|
+
return this.getIdOrFail(resource).then(function (parent) {
|
|
1765
|
+
return _this._getChildrenOf(parent, requestOptions);
|
|
1766
|
+
});
|
|
1767
|
+
};
|
|
1768
|
+
ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
|
|
1769
|
+
var _this = this;
|
|
1770
|
+
if (_items === void 0) { _items = []; }
|
|
1771
|
+
return this.connector
|
|
1772
|
+
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
1773
|
+
parent: parent,
|
|
1774
|
+
})
|
|
1775
|
+
.then(function (items) {
|
|
1776
|
+
var recursivePromises = [];
|
|
1777
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
1778
|
+
var item = items_1[_i];
|
|
1779
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(item), {
|
|
1780
|
+
id: item.resource.id,
|
|
1781
|
+
});
|
|
1782
|
+
_items.push(item);
|
|
1783
|
+
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
1784
|
+
recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
|
|
1526
1785
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1786
|
+
}
|
|
1787
|
+
if (recursivePromises.length) {
|
|
1788
|
+
return CancelablePromise.all(recursivePromises).then(function () {
|
|
1789
|
+
return _items;
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
return _items;
|
|
1529
1793
|
});
|
|
1530
|
-
}
|
|
1531
|
-
update(resource, data) {
|
|
1532
|
-
|
|
1794
|
+
};
|
|
1795
|
+
ResourcesControl.prototype.update = function (resource, data) {
|
|
1796
|
+
var _this = this;
|
|
1797
|
+
return this.getId(resource).then(function (id) {
|
|
1533
1798
|
if (id !== undefined) {
|
|
1534
|
-
return
|
|
1799
|
+
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
1535
1800
|
}
|
|
1536
1801
|
});
|
|
1537
|
-
}
|
|
1802
|
+
};
|
|
1538
1803
|
/**
|
|
1539
1804
|
* Fast way to delete resource from NGW and clean cache.
|
|
1540
1805
|
* @param resource - Resource definition
|
|
1541
1806
|
*/
|
|
1542
|
-
delete(resource) {
|
|
1543
|
-
|
|
1807
|
+
ResourcesControl.prototype.delete = function (resource) {
|
|
1808
|
+
var _this = this;
|
|
1809
|
+
return this.getId(resource).then(function (id) {
|
|
1544
1810
|
if (id !== undefined) {
|
|
1545
|
-
return
|
|
1546
|
-
|
|
1811
|
+
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
1812
|
+
_this._cleanResourceItemCache(id);
|
|
1547
1813
|
return undefined;
|
|
1548
1814
|
});
|
|
1549
1815
|
}
|
|
1550
1816
|
});
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1817
|
+
};
|
|
1818
|
+
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
1819
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1820
|
+
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
1821
|
+
return __generator(this, function (_b) {
|
|
1822
|
+
switch (_b.label) {
|
|
1823
|
+
case 0:
|
|
1824
|
+
all = this.cache.all();
|
|
1825
|
+
toDelete = [];
|
|
1826
|
+
_i = 0, all_1 = all;
|
|
1827
|
+
_b.label = 1;
|
|
1828
|
+
case 1:
|
|
1829
|
+
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
1830
|
+
c = all_1[_i];
|
|
1831
|
+
cid = c.options && c.options.id;
|
|
1832
|
+
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
1833
|
+
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
1834
|
+
if (cid === id) {
|
|
1835
|
+
toDelete.push(c);
|
|
1836
|
+
}
|
|
1837
|
+
return [3 /*break*/, 4];
|
|
1838
|
+
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
1839
|
+
case 3:
|
|
1840
|
+
rid = _b.sent();
|
|
1841
|
+
if (rid === id) {
|
|
1842
|
+
toDelete.push(c);
|
|
1843
|
+
}
|
|
1844
|
+
_b.label = 4;
|
|
1845
|
+
case 4:
|
|
1846
|
+
_i++;
|
|
1847
|
+
return [3 /*break*/, 1];
|
|
1848
|
+
case 5:
|
|
1849
|
+
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
1850
|
+
d = toDelete_1[_a];
|
|
1851
|
+
this.cache.delete(d);
|
|
1852
|
+
}
|
|
1853
|
+
return [2 /*return*/];
|
|
1568
1854
|
}
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1855
|
+
});
|
|
1856
|
+
});
|
|
1857
|
+
};
|
|
1858
|
+
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
1859
|
+
var _this = this;
|
|
1860
|
+
var promise = function () {
|
|
1861
|
+
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
1862
|
+
};
|
|
1577
1863
|
return this.cache
|
|
1578
1864
|
.add('resource.item', promise, {
|
|
1579
|
-
id,
|
|
1865
|
+
id: id,
|
|
1580
1866
|
})
|
|
1581
|
-
.catch((er)
|
|
1867
|
+
.catch(function (er) {
|
|
1582
1868
|
if (!(er instanceof ResourceNotFoundError)) {
|
|
1583
1869
|
throw er;
|
|
1584
1870
|
}
|
|
1585
1871
|
return undefined;
|
|
1586
1872
|
});
|
|
1587
|
-
}
|
|
1588
|
-
_fetchResourceBy(resource, requestOptions) {
|
|
1589
|
-
return this.getMany(resource, requestOptions).then((resources)
|
|
1873
|
+
};
|
|
1874
|
+
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
1875
|
+
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
1590
1876
|
return resources[0];
|
|
1591
1877
|
});
|
|
1592
|
-
}
|
|
1593
|
-
_resourceCacheFilter(resource) {
|
|
1594
|
-
return CancelablePromise.all(this.cache.matchAll('resource.item')).then((resources)
|
|
1595
|
-
|
|
1596
|
-
resources.filter((x)
|
|
1878
|
+
};
|
|
1879
|
+
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
1880
|
+
return CancelablePromise.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
1881
|
+
var items = [];
|
|
1882
|
+
resources.filter(function (x) {
|
|
1597
1883
|
if (x) {
|
|
1598
1884
|
// identical by uniq props
|
|
1599
1885
|
if (resource.keyname && x.resource.keyname) {
|
|
@@ -1607,23 +1893,24 @@ class ResourcesControl {
|
|
|
1607
1893
|
});
|
|
1608
1894
|
return items;
|
|
1609
1895
|
});
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1896
|
+
};
|
|
1897
|
+
return ResourcesControl;
|
|
1898
|
+
}());
|
|
1612
1899
|
|
|
1613
1900
|
function apiRequest(opt) {
|
|
1614
|
-
|
|
1615
|
-
return new CancelablePromise((resolve, reject)
|
|
1901
|
+
var params = opt.params;
|
|
1902
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
1616
1903
|
opt.connector
|
|
1617
1904
|
.connect()
|
|
1618
|
-
.then((apiItems)
|
|
1619
|
-
|
|
1905
|
+
.then(function (apiItems) {
|
|
1906
|
+
var apiItem = apiItems && apiItems[opt.name];
|
|
1620
1907
|
if (apiItem) {
|
|
1621
|
-
apiItem = [
|
|
1622
|
-
|
|
1908
|
+
apiItem = __spreadArray([], apiItem, true);
|
|
1909
|
+
var url = apiItem.shift();
|
|
1623
1910
|
if (apiItem.length) {
|
|
1624
|
-
|
|
1625
|
-
for (
|
|
1626
|
-
|
|
1911
|
+
var replaceParams = {};
|
|
1912
|
+
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
1913
|
+
var arg = apiItem[fry];
|
|
1627
1914
|
replaceParams[fry] = '{' + arg + '}';
|
|
1628
1915
|
if (params[arg] === undefined) {
|
|
1629
1916
|
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
@@ -1635,21 +1922,21 @@ function apiRequest(opt) {
|
|
|
1635
1922
|
}
|
|
1636
1923
|
// Transfer part of the parameters from `params` to the URL string
|
|
1637
1924
|
if (params) {
|
|
1638
|
-
|
|
1639
|
-
|
|
1925
|
+
var paramArray_1 = [];
|
|
1926
|
+
var paramList = params.paramList;
|
|
1640
1927
|
if (Array.isArray(paramList)) {
|
|
1641
1928
|
delete params.paramList;
|
|
1642
|
-
paramList.forEach((x)
|
|
1643
|
-
|
|
1929
|
+
paramList.forEach(function (x) {
|
|
1930
|
+
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
1644
1931
|
});
|
|
1645
1932
|
}
|
|
1646
|
-
for (
|
|
1933
|
+
for (var p in params) {
|
|
1647
1934
|
if (apiItem.indexOf(p) === -1) {
|
|
1648
|
-
|
|
1935
|
+
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
1649
1936
|
}
|
|
1650
1937
|
}
|
|
1651
|
-
if (
|
|
1652
|
-
url = url + '?' +
|
|
1938
|
+
if (paramArray_1.length) {
|
|
1939
|
+
url = url + '?' + paramArray_1.join('&');
|
|
1653
1940
|
}
|
|
1654
1941
|
}
|
|
1655
1942
|
if (url) {
|
|
@@ -1663,20 +1950,20 @@ function apiRequest(opt) {
|
|
|
1663
1950
|
resolve(undefined);
|
|
1664
1951
|
}
|
|
1665
1952
|
})
|
|
1666
|
-
.catch((er)
|
|
1953
|
+
.catch(function (er) {
|
|
1667
1954
|
reject(er);
|
|
1668
1955
|
});
|
|
1669
1956
|
});
|
|
1670
1957
|
}
|
|
1671
1958
|
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1959
|
+
var ID = 0;
|
|
1960
|
+
var NgwConnector$1 = /** @class */ (function () {
|
|
1961
|
+
function NgwConnector(options) {
|
|
1675
1962
|
this.options = options;
|
|
1676
1963
|
this.id = ID++;
|
|
1677
1964
|
this.emitter = new events.exports.EventEmitter();
|
|
1678
1965
|
this.routeStr = '/api/component/pyramid/route';
|
|
1679
|
-
|
|
1966
|
+
var exist = findConnector(options);
|
|
1680
1967
|
if (exist) {
|
|
1681
1968
|
return exist;
|
|
1682
1969
|
}
|
|
@@ -1688,19 +1975,19 @@ class NgwConnector$1 {
|
|
|
1688
1975
|
addConnector(this);
|
|
1689
1976
|
}
|
|
1690
1977
|
}
|
|
1691
|
-
|
|
1978
|
+
NgwConnector.create = function (options) {
|
|
1692
1979
|
return new this(options);
|
|
1693
|
-
}
|
|
1980
|
+
};
|
|
1694
1981
|
/**
|
|
1695
1982
|
* Fast way to specify the connection address to NextGIS Web.
|
|
1696
1983
|
* The current connection will be severed.
|
|
1697
1984
|
* @param baseUrl - NGW url
|
|
1698
1985
|
*/
|
|
1699
|
-
setNgw(baseUrl) {
|
|
1986
|
+
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
1700
1987
|
this.logout();
|
|
1701
1988
|
this.options.baseUrl = baseUrl;
|
|
1702
1989
|
addConnector(this);
|
|
1703
|
-
}
|
|
1990
|
+
};
|
|
1704
1991
|
/**
|
|
1705
1992
|
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
1706
1993
|
* @remarks
|
|
@@ -1714,101 +2001,105 @@ class NgwConnector$1 {
|
|
|
1714
2001
|
* .catch((er) => console.log('Connection problem', er));
|
|
1715
2002
|
* ```
|
|
1716
2003
|
*/
|
|
1717
|
-
connect() {
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
reject(er);
|
|
1728
|
-
});
|
|
1729
|
-
};
|
|
1730
|
-
if (auth) {
|
|
1731
|
-
const { login, password } = auth;
|
|
1732
|
-
if (login && password) {
|
|
1733
|
-
return this.getUserInfo({ login, password })
|
|
1734
|
-
.then(() => {
|
|
1735
|
-
makeQuery();
|
|
2004
|
+
NgwConnector.prototype.connect = function () {
|
|
2005
|
+
var _this = this;
|
|
2006
|
+
var cache = new Cache();
|
|
2007
|
+
var auth = this.options.auth;
|
|
2008
|
+
var makeConnect = function () {
|
|
2009
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
2010
|
+
var makeQuery = function () {
|
|
2011
|
+
return _this.makeQuery(_this.routeStr, {}, {})
|
|
2012
|
+
.then(function (route) {
|
|
2013
|
+
resolve(route);
|
|
1736
2014
|
})
|
|
1737
|
-
.catch((er)
|
|
2015
|
+
.catch(function (er) {
|
|
2016
|
+
reject(er);
|
|
2017
|
+
});
|
|
2018
|
+
};
|
|
2019
|
+
if (auth) {
|
|
2020
|
+
var login = auth.login, password = auth.password;
|
|
2021
|
+
if (login && password) {
|
|
2022
|
+
return _this.getUserInfo({ login: login, password: password })
|
|
2023
|
+
.then(function () {
|
|
2024
|
+
makeQuery();
|
|
2025
|
+
})
|
|
2026
|
+
.catch(function (er) { return reject(er); });
|
|
2027
|
+
}
|
|
1738
2028
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
}
|
|
2029
|
+
return makeQuery();
|
|
2030
|
+
});
|
|
2031
|
+
};
|
|
1742
2032
|
return cache.add('route', makeConnect, {
|
|
1743
2033
|
id: this.id,
|
|
1744
|
-
auth,
|
|
2034
|
+
auth: auth,
|
|
1745
2035
|
baseUrl: this.options.baseUrl,
|
|
1746
2036
|
});
|
|
1747
|
-
}
|
|
2037
|
+
};
|
|
1748
2038
|
/**
|
|
1749
2039
|
* Quick way to change NextGIS Web user.
|
|
1750
2040
|
* @param credentials - New user credentials
|
|
1751
2041
|
*/
|
|
1752
|
-
login(credentials) {
|
|
2042
|
+
NgwConnector.prototype.login = function (credentials) {
|
|
1753
2043
|
this.logout();
|
|
1754
2044
|
addConnector(this);
|
|
1755
2045
|
return this.getUserInfo(credentials);
|
|
1756
|
-
}
|
|
2046
|
+
};
|
|
1757
2047
|
/**
|
|
1758
2048
|
* Disconnecting a user. Aborting all current requests
|
|
1759
2049
|
*/
|
|
1760
|
-
logout() {
|
|
2050
|
+
NgwConnector.prototype.logout = function () {
|
|
1761
2051
|
removeConnector(this);
|
|
1762
2052
|
this.options.auth = undefined;
|
|
1763
2053
|
this.user = undefined;
|
|
1764
2054
|
this.emitter.emit('logout');
|
|
1765
2055
|
this.resources.cache.clean();
|
|
1766
|
-
}
|
|
1767
|
-
getUserInfo(credentials) {
|
|
2056
|
+
};
|
|
2057
|
+
NgwConnector.prototype.getUserInfo = function (credentials) {
|
|
2058
|
+
var _this = this;
|
|
1768
2059
|
if (this.user && this.user.id) {
|
|
1769
2060
|
return CancelablePromise.resolve(this.user);
|
|
1770
2061
|
}
|
|
1771
2062
|
if (credentials) {
|
|
1772
2063
|
this.options.auth = credentials;
|
|
1773
2064
|
}
|
|
1774
|
-
|
|
2065
|
+
var options = {
|
|
1775
2066
|
headers: this.getAuthorizationHeaders(credentials),
|
|
1776
2067
|
// withCredentials: true
|
|
1777
2068
|
};
|
|
1778
2069
|
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
1779
2070
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
1780
|
-
.then((data)
|
|
1781
|
-
|
|
1782
|
-
|
|
2071
|
+
.then(function (data) {
|
|
2072
|
+
_this.user = data;
|
|
2073
|
+
_this.emitter.emit('login', data);
|
|
1783
2074
|
return data;
|
|
1784
2075
|
})
|
|
1785
|
-
.catch((er)
|
|
1786
|
-
|
|
2076
|
+
.catch(function (er) {
|
|
2077
|
+
_this.emitter.emit('login:error', er);
|
|
1787
2078
|
throw er;
|
|
1788
2079
|
});
|
|
1789
|
-
}
|
|
2080
|
+
};
|
|
1790
2081
|
/**
|
|
1791
2082
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
1792
2083
|
*/
|
|
1793
|
-
getAuthorizationHeaders(credentials) {
|
|
1794
|
-
|
|
2084
|
+
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
2085
|
+
var client = this.makeClientId(credentials);
|
|
1795
2086
|
if (client) {
|
|
1796
2087
|
return {
|
|
1797
2088
|
Authorization: 'Basic ' + client,
|
|
1798
2089
|
};
|
|
1799
2090
|
}
|
|
1800
|
-
}
|
|
1801
|
-
makeClientId(credentials) {
|
|
2091
|
+
};
|
|
2092
|
+
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
1802
2093
|
credentials = credentials || this.options.auth;
|
|
1803
2094
|
if (credentials) {
|
|
1804
|
-
|
|
1805
|
-
|
|
2095
|
+
var login = credentials.login, password = credentials.password;
|
|
2096
|
+
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
1806
2097
|
// @ts-ignore
|
|
1807
2098
|
{
|
|
1808
2099
|
return window.btoa(str);
|
|
1809
2100
|
}
|
|
1810
2101
|
}
|
|
1811
|
-
}
|
|
2102
|
+
};
|
|
1812
2103
|
/**
|
|
1813
2104
|
* Send request to NGW api router.
|
|
1814
2105
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -1838,25 +2129,27 @@ class NgwConnector$1 {
|
|
|
1838
2129
|
*
|
|
1839
2130
|
* ```
|
|
1840
2131
|
*/
|
|
1841
|
-
apiRequest(name, params_
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
2132
|
+
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
2133
|
+
var _this = this;
|
|
2134
|
+
if (params_ === void 0) { params_ = {}; }
|
|
2135
|
+
if (requestOptions === void 0) { requestOptions = {}; }
|
|
2136
|
+
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
2137
|
+
var params = objectRemoveEmpty(params_);
|
|
2138
|
+
var makeApiRequest = function () {
|
|
2139
|
+
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
2140
|
+
};
|
|
1845
2141
|
if (requestOptions.cache && method === 'GET') {
|
|
1846
|
-
|
|
1847
|
-
return cache.add(name, makeApiRequest, {
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
auth: this.options.auth,
|
|
1855
|
-
}),
|
|
1856
|
-
});
|
|
2142
|
+
var cache = new Cache();
|
|
2143
|
+
return cache.add(name, makeApiRequest, __assign({ params: params }, objectRemoveEmpty({
|
|
2144
|
+
headers: headers,
|
|
2145
|
+
withCredentials: withCredentials,
|
|
2146
|
+
responseType: responseType,
|
|
2147
|
+
baseUrl: this.options.baseUrl,
|
|
2148
|
+
auth: this.options.auth,
|
|
2149
|
+
})));
|
|
1857
2150
|
}
|
|
1858
2151
|
return makeApiRequest();
|
|
1859
|
-
}
|
|
2152
|
+
};
|
|
1860
2153
|
/**
|
|
1861
2154
|
* Shortcut method for send POST request to NGW.
|
|
1862
2155
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -1870,62 +2163,63 @@ class NgwConnector$1 {
|
|
|
1870
2163
|
* .catch((error) => console.warn(error));
|
|
1871
2164
|
* ```
|
|
1872
2165
|
*/
|
|
1873
|
-
post(name, options, params) {
|
|
2166
|
+
NgwConnector.prototype.post = function (name, options, params) {
|
|
1874
2167
|
options = options || {};
|
|
1875
2168
|
options.method = 'POST';
|
|
1876
2169
|
return this.apiRequest(name, params, options);
|
|
1877
|
-
}
|
|
2170
|
+
};
|
|
1878
2171
|
/**
|
|
1879
2172
|
* Shortcut method for send GET request to NGW.
|
|
1880
2173
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1881
2174
|
* @param options - Request options
|
|
1882
2175
|
* @param params - Request item params or query params
|
|
1883
2176
|
*/
|
|
1884
|
-
get(name, options, params) {
|
|
2177
|
+
NgwConnector.prototype.get = function (name, options, params) {
|
|
1885
2178
|
options = options || {};
|
|
1886
2179
|
options.method = 'GET';
|
|
1887
2180
|
return this.apiRequest(name, params, options);
|
|
1888
|
-
}
|
|
2181
|
+
};
|
|
1889
2182
|
/**
|
|
1890
2183
|
* Shortcut method for send PATCH request to NGW.
|
|
1891
2184
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1892
2185
|
* @param options - Request options
|
|
1893
2186
|
* @param params - Request item params or query params
|
|
1894
2187
|
*/
|
|
1895
|
-
patch(name, options, params) {
|
|
2188
|
+
NgwConnector.prototype.patch = function (name, options, params) {
|
|
1896
2189
|
options = options || {};
|
|
1897
2190
|
options.method = 'PATCH';
|
|
1898
2191
|
return this.apiRequest(name, params, options);
|
|
1899
|
-
}
|
|
2192
|
+
};
|
|
1900
2193
|
/**
|
|
1901
2194
|
* Shortcut method for send PUT request to NGW.
|
|
1902
2195
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1903
2196
|
* @param options - Request options
|
|
1904
2197
|
* @param params - Request item params or query params
|
|
1905
2198
|
*/
|
|
1906
|
-
put(name, options, params) {
|
|
2199
|
+
NgwConnector.prototype.put = function (name, options, params) {
|
|
1907
2200
|
options = options || {};
|
|
1908
2201
|
options.method = 'PUT';
|
|
1909
2202
|
return this.apiRequest(name, params, options);
|
|
1910
|
-
}
|
|
2203
|
+
};
|
|
1911
2204
|
/**
|
|
1912
2205
|
* Shortcut method for send DELETE request to NGW.
|
|
1913
2206
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
1914
2207
|
* @param options - Request options
|
|
1915
2208
|
* @param params - Request item params or query params
|
|
1916
2209
|
*/
|
|
1917
|
-
delete(name, options, params) {
|
|
2210
|
+
NgwConnector.prototype.delete = function (name, options, params) {
|
|
1918
2211
|
options = options || {};
|
|
1919
2212
|
options.method = 'DELETE';
|
|
1920
2213
|
return this.apiRequest(name, params, options);
|
|
1921
|
-
}
|
|
2214
|
+
};
|
|
1922
2215
|
/**
|
|
1923
2216
|
* Send request to NGW.
|
|
1924
2217
|
* @param url - URL address to NGW
|
|
1925
2218
|
* @param params - Query params
|
|
1926
2219
|
* @param options - Request options
|
|
1927
2220
|
*/
|
|
1928
|
-
makeQuery(url, params, options
|
|
2221
|
+
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
2222
|
+
if (options === void 0) { options = {}; }
|
|
1929
2223
|
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
1930
2224
|
if (url) {
|
|
1931
2225
|
if (params) {
|
|
@@ -1938,112 +2232,110 @@ class NgwConnector$1 {
|
|
|
1938
2232
|
else {
|
|
1939
2233
|
throw new Error('Empty `url` not allowed');
|
|
1940
2234
|
}
|
|
1941
|
-
}
|
|
2235
|
+
};
|
|
1942
2236
|
// -------------------------------------------------------------------------
|
|
1943
2237
|
// Resource Methods
|
|
1944
2238
|
// -------------------------------------------------------------------------
|
|
1945
2239
|
/**
|
|
1946
2240
|
* {@inheritDoc ResourcesControl.getOne}
|
|
1947
2241
|
*/
|
|
1948
|
-
getResource(resource, requestOptions) {
|
|
2242
|
+
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
1949
2243
|
return this.resources.getOne(resource, requestOptions);
|
|
1950
|
-
}
|
|
2244
|
+
};
|
|
1951
2245
|
/**
|
|
1952
2246
|
* {@inheritDoc ResourcesControl.getOneOrFail}
|
|
1953
2247
|
*/
|
|
1954
|
-
getResourceOrFail(resource, requestOptions) {
|
|
2248
|
+
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
1955
2249
|
return this.resources.getOneOrFail(resource, requestOptions);
|
|
1956
|
-
}
|
|
2250
|
+
};
|
|
1957
2251
|
/**
|
|
1958
2252
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
1959
2253
|
*/
|
|
1960
|
-
getResourceBy(resource) {
|
|
2254
|
+
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
1961
2255
|
return this.resources.getOne(resource);
|
|
1962
|
-
}
|
|
2256
|
+
};
|
|
1963
2257
|
/**
|
|
1964
2258
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
1965
2259
|
*/
|
|
1966
|
-
getResourceByKeyname(keyname) {
|
|
2260
|
+
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
1967
2261
|
return this.resources.getOne(keyname);
|
|
1968
|
-
}
|
|
2262
|
+
};
|
|
1969
2263
|
/**
|
|
1970
2264
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
1971
2265
|
*/
|
|
1972
|
-
getResourceById(id) {
|
|
2266
|
+
NgwConnector.prototype.getResourceById = function (id) {
|
|
1973
2267
|
return this.resources.getOne(id);
|
|
1974
|
-
}
|
|
2268
|
+
};
|
|
1975
2269
|
/**
|
|
1976
2270
|
* {@inheritDoc ResourcesControl.getId}
|
|
1977
2271
|
*/
|
|
1978
|
-
getResourceId(resource, requestOptions) {
|
|
2272
|
+
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
1979
2273
|
return this.resources.getId(resource, requestOptions);
|
|
1980
|
-
}
|
|
2274
|
+
};
|
|
1981
2275
|
/**
|
|
1982
2276
|
* {@inheritDoc ResourcesControl.getIdOrFail}
|
|
1983
2277
|
*/
|
|
1984
|
-
getResourceIdOrFail(resource, requestOptions) {
|
|
2278
|
+
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
1985
2279
|
return this.resources.getIdOrFail(resource, requestOptions);
|
|
1986
|
-
}
|
|
2280
|
+
};
|
|
1987
2281
|
/**
|
|
1988
2282
|
* {@inheritDoc ResourcesControl.getMany}
|
|
1989
2283
|
*/
|
|
1990
|
-
getResourcesBy(resource, requestOptions) {
|
|
2284
|
+
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
1991
2285
|
return this.resources.getMany(resource, requestOptions);
|
|
1992
|
-
}
|
|
2286
|
+
};
|
|
1993
2287
|
/**
|
|
1994
2288
|
* {@inheritDoc ResourcesControl.getParent}
|
|
1995
2289
|
*/
|
|
1996
|
-
getResourceParent(resource, requestOptions) {
|
|
2290
|
+
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
1997
2291
|
return this.resources.getParent(resource, requestOptions);
|
|
1998
|
-
}
|
|
2292
|
+
};
|
|
1999
2293
|
/**
|
|
2000
2294
|
* {@inheritDoc ResourcesControl.getChildrenOf}
|
|
2001
2295
|
*/
|
|
2002
|
-
getResourceChildren(resource, requestOptions) {
|
|
2296
|
+
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
2003
2297
|
return this.resources.getChildrenOf(resource, requestOptions);
|
|
2004
|
-
}
|
|
2298
|
+
};
|
|
2005
2299
|
/**
|
|
2006
2300
|
* {@inheritDoc ResourcesControl.update}
|
|
2007
2301
|
*/
|
|
2008
|
-
updateResource(resource, data) {
|
|
2302
|
+
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
2009
2303
|
return this.resources.update(resource, data);
|
|
2010
|
-
}
|
|
2304
|
+
};
|
|
2011
2305
|
/**
|
|
2012
2306
|
* {@inheritDoc ResourcesControl.delete}
|
|
2013
2307
|
*/
|
|
2014
|
-
deleteResource(resource) {
|
|
2308
|
+
NgwConnector.prototype.deleteResource = function (resource) {
|
|
2015
2309
|
return this.resources.delete(resource);
|
|
2016
|
-
}
|
|
2310
|
+
};
|
|
2017
2311
|
/**
|
|
2018
2312
|
* @internal
|
|
2019
2313
|
*/
|
|
2020
|
-
_loadData(url, options) {
|
|
2314
|
+
NgwConnector.prototype._loadData = function (url, options) {
|
|
2315
|
+
var _this = this;
|
|
2021
2316
|
options.responseType = options.responseType || 'json';
|
|
2022
|
-
return new CancelablePromise((resolve, reject, onCancel)
|
|
2023
|
-
if (
|
|
2317
|
+
return new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2318
|
+
if (_this.user) {
|
|
2024
2319
|
options = options || {};
|
|
2025
2320
|
// options.withCredentials = true;
|
|
2026
|
-
options.headers = {
|
|
2027
|
-
...this.getAuthorizationHeaders(),
|
|
2028
|
-
...options.headers,
|
|
2029
|
-
};
|
|
2321
|
+
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
2030
2322
|
}
|
|
2031
2323
|
loadData(url, resolve, options, reject, onCancel);
|
|
2032
|
-
}).catch((httpError)
|
|
2324
|
+
}).catch(function (httpError) {
|
|
2033
2325
|
if (httpError instanceof CancelablePromise.CancelError) ;
|
|
2034
2326
|
else {
|
|
2035
2327
|
// @ts-ignore
|
|
2036
2328
|
{
|
|
2037
2329
|
console.warn('DEV WARN', httpError);
|
|
2038
2330
|
}
|
|
2039
|
-
|
|
2331
|
+
var er = _this._handleHttpError(httpError);
|
|
2040
2332
|
if (er) {
|
|
2041
2333
|
throw er;
|
|
2042
2334
|
}
|
|
2043
2335
|
}
|
|
2044
2336
|
});
|
|
2045
|
-
}
|
|
2046
|
-
_handleHttpError(er) {
|
|
2337
|
+
};
|
|
2338
|
+
NgwConnector.prototype._handleHttpError = function (er) {
|
|
2047
2339
|
if (er) {
|
|
2048
2340
|
if (er instanceof NgwError) {
|
|
2049
2341
|
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
@@ -2055,12 +2347,13 @@ class NgwConnector$1 {
|
|
|
2055
2347
|
}
|
|
2056
2348
|
}
|
|
2057
2349
|
return er;
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2350
|
+
};
|
|
2351
|
+
NgwConnector.errors = {
|
|
2352
|
+
NgwError: NgwError,
|
|
2353
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
2354
|
+
};
|
|
2355
|
+
return NgwConnector;
|
|
2356
|
+
}());
|
|
2064
2357
|
|
|
2065
2358
|
/**
|
|
2066
2359
|
* A lightweight HTTP client optimized for use with {@link http://docs.nextgis.ru/docs_ngweb_dev/doc/developer/toc.html | NextGIS Web} API
|
|
@@ -2074,64 +2367,115 @@ NgwConnector$1.errors = {
|
|
|
2074
2367
|
// export { NgwConnector };
|
|
2075
2368
|
var NgwConnector = NgwConnector$1;
|
|
2076
2369
|
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2370
|
+
var NgwProvider = /** @class */ (function (_super) {
|
|
2371
|
+
__extends(NgwProvider, _super);
|
|
2372
|
+
function NgwProvider(options) {
|
|
2373
|
+
var _this = _super.call(this, options) || this;
|
|
2374
|
+
_this.caseInsensitive = true;
|
|
2375
|
+
_this.searchUrl = 'https://maxim.nextgis.com';
|
|
2376
|
+
_this.searchResources = [];
|
|
2377
|
+
_this.requests = [];
|
|
2378
|
+
_this.connector =
|
|
2085
2379
|
options.connector ||
|
|
2086
2380
|
new NgwConnector({
|
|
2087
|
-
baseUrl:
|
|
2381
|
+
baseUrl: _this.searchUrl,
|
|
2088
2382
|
});
|
|
2089
|
-
|
|
2383
|
+
_this.searchResources = options.searchResources;
|
|
2384
|
+
return _this;
|
|
2090
2385
|
}
|
|
2091
|
-
abort() {
|
|
2092
|
-
this.requests.forEach((x)
|
|
2386
|
+
NgwProvider.prototype.abort = function () {
|
|
2387
|
+
this.requests.forEach(function (x) {
|
|
2093
2388
|
x.cancel();
|
|
2094
2389
|
});
|
|
2095
2390
|
this.requests = [];
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2391
|
+
};
|
|
2392
|
+
NgwProvider.prototype.search = function (like) {
|
|
2393
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
2394
|
+
var _loop_1, this_1, _i, _a, resource;
|
|
2395
|
+
var _this = this;
|
|
2396
|
+
return __generator(this, function (_b) {
|
|
2397
|
+
switch (_b.label) {
|
|
2398
|
+
case 0:
|
|
2399
|
+
_loop_1 = function (resource) {
|
|
2400
|
+
var limit, request, resp, entries, _loop_2, _c, _d, item;
|
|
2401
|
+
return __generator(this, function (_e) {
|
|
2402
|
+
switch (_e.label) {
|
|
2403
|
+
case 0:
|
|
2404
|
+
limit = resource.limit || 300;
|
|
2405
|
+
request = this_1.connector.get('feature_layer.store', {
|
|
2406
|
+
headers: { RANGE: "items=0-".concat(limit) },
|
|
2407
|
+
}, {
|
|
2408
|
+
id: resource.id,
|
|
2409
|
+
like: like,
|
|
2410
|
+
});
|
|
2411
|
+
this_1.requests.push(request);
|
|
2412
|
+
request.catch(function (er) {
|
|
2413
|
+
console.warn(er);
|
|
2414
|
+
});
|
|
2415
|
+
return [4 /*yield*/, __await(request)];
|
|
2416
|
+
case 1:
|
|
2417
|
+
resp = _e.sent();
|
|
2418
|
+
entries = [];
|
|
2419
|
+
if (resp) {
|
|
2420
|
+
resp.forEach(function (x) {
|
|
2421
|
+
entries.push(__assign({ query: like, resourceId: resource.id }, x));
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2424
|
+
_loop_2 = function (item) {
|
|
2425
|
+
return __generator(this, function (_f) {
|
|
2426
|
+
switch (_f.label) {
|
|
2427
|
+
case 0:
|
|
2428
|
+
item.result = function () { return _this.result(item); };
|
|
2429
|
+
return [4 /*yield*/, __await(item)];
|
|
2430
|
+
case 1: return [4 /*yield*/, _f.sent()];
|
|
2431
|
+
case 2:
|
|
2432
|
+
_f.sent();
|
|
2433
|
+
return [2 /*return*/];
|
|
2434
|
+
}
|
|
2435
|
+
});
|
|
2436
|
+
};
|
|
2437
|
+
_c = 0, _d = this_1._items(entries);
|
|
2438
|
+
_e.label = 2;
|
|
2439
|
+
case 2:
|
|
2440
|
+
if (!(_c < _d.length)) return [3 /*break*/, 5];
|
|
2441
|
+
item = _d[_c];
|
|
2442
|
+
return [5 /*yield**/, _loop_2(item)];
|
|
2443
|
+
case 3:
|
|
2444
|
+
_e.sent();
|
|
2445
|
+
_e.label = 4;
|
|
2446
|
+
case 4:
|
|
2447
|
+
_c++;
|
|
2448
|
+
return [3 /*break*/, 2];
|
|
2449
|
+
case 5: return [2 /*return*/];
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
};
|
|
2453
|
+
this_1 = this;
|
|
2454
|
+
_i = 0, _a = this.searchResources;
|
|
2455
|
+
_b.label = 1;
|
|
2456
|
+
case 1:
|
|
2457
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
2458
|
+
resource = _a[_i];
|
|
2459
|
+
return [5 /*yield**/, _loop_1(resource)];
|
|
2460
|
+
case 2:
|
|
2461
|
+
_b.sent();
|
|
2462
|
+
_b.label = 3;
|
|
2463
|
+
case 3:
|
|
2464
|
+
_i++;
|
|
2465
|
+
return [3 /*break*/, 1];
|
|
2466
|
+
case 4: return [2 /*return*/];
|
|
2467
|
+
}
|
|
2109
2468
|
});
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
entries.push({
|
|
2115
|
-
query: like,
|
|
2116
|
-
resourceId: resource.id,
|
|
2117
|
-
...x,
|
|
2118
|
-
});
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
for (const item of this._items(entries)) {
|
|
2122
|
-
item.result = () => this.result(item);
|
|
2123
|
-
yield item;
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
result(item) {
|
|
2128
|
-
const req = this.connector
|
|
2469
|
+
});
|
|
2470
|
+
};
|
|
2471
|
+
NgwProvider.prototype.result = function (item) {
|
|
2472
|
+
var req = this.connector
|
|
2129
2473
|
.get('feature_layer.feature.item_extent', null, {
|
|
2130
2474
|
id: item.resourceId,
|
|
2131
2475
|
fid: item.featureId,
|
|
2132
2476
|
})
|
|
2133
|
-
.then((x)
|
|
2134
|
-
|
|
2477
|
+
.then(function (x) {
|
|
2478
|
+
var e = x.extent;
|
|
2135
2479
|
return {
|
|
2136
2480
|
text: item.text,
|
|
2137
2481
|
extent: [e.minLon, e.minLat, e.maxLon, e.maxLat],
|
|
@@ -2139,11 +2483,12 @@ class NgwProvider extends BaseProvider {
|
|
|
2139
2483
|
});
|
|
2140
2484
|
this.requests.push(req);
|
|
2141
2485
|
return req;
|
|
2142
|
-
}
|
|
2143
|
-
_items(entries) {
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2486
|
+
};
|
|
2487
|
+
NgwProvider.prototype._items = function (entries) {
|
|
2488
|
+
var _this = this;
|
|
2489
|
+
var items = [];
|
|
2490
|
+
entries.forEach(function (entry) {
|
|
2491
|
+
var meta = _this.searchResources.find(function (x) { return x.id === entry.resourceId; });
|
|
2147
2492
|
if (meta) {
|
|
2148
2493
|
items.push({
|
|
2149
2494
|
query: entry.query,
|
|
@@ -2154,72 +2499,107 @@ class NgwProvider extends BaseProvider {
|
|
|
2154
2499
|
}
|
|
2155
2500
|
});
|
|
2156
2501
|
return items;
|
|
2157
|
-
}
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2502
|
+
};
|
|
2503
|
+
return NgwProvider;
|
|
2504
|
+
}(BaseProvider));
|
|
2505
|
+
|
|
2506
|
+
var NominatimProvider = /** @class */ (function (_super) {
|
|
2507
|
+
__extends(NominatimProvider, _super);
|
|
2508
|
+
function NominatimProvider(options) {
|
|
2509
|
+
var _this = _super.call(this, options) || this;
|
|
2510
|
+
_this.searchUrl = 'https://nominatim.openstreetmap.org';
|
|
2511
|
+
_this._requests = [];
|
|
2512
|
+
return _this;
|
|
2513
|
+
}
|
|
2514
|
+
NominatimProvider.prototype.abort = function () {
|
|
2515
|
+
this._requests.forEach(function (x) { return x.cancel(); });
|
|
2168
2516
|
this._requests = [];
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2517
|
+
};
|
|
2518
|
+
NominatimProvider.prototype.search = function (val) {
|
|
2519
|
+
return __asyncGenerator(this, arguments, function search_1() {
|
|
2520
|
+
var url, request, items, _loop_1, _i, items_1, i;
|
|
2521
|
+
var _this = this;
|
|
2522
|
+
return __generator(this, function (_a) {
|
|
2523
|
+
switch (_a.label) {
|
|
2524
|
+
case 0:
|
|
2525
|
+
url = fixUrlStr(
|
|
2526
|
+
// `${this.baseUrl}/search?format=geojson&polygon_geojson=1${window.locale === 'ru' ? '&accept-language=ru-RU,en-US' : ''}&q=${val}`
|
|
2527
|
+
"".concat(this.searchUrl, "/search?format=geojson&polygon_geojson=1&q=").concat(val));
|
|
2528
|
+
request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
2529
|
+
var xhr = new XMLHttpRequest();
|
|
2530
|
+
xhr.open('GET', url, true);
|
|
2531
|
+
xhr.onload = function () {
|
|
2532
|
+
try {
|
|
2533
|
+
var geojson = JSON.parse(xhr.responseText);
|
|
2534
|
+
var features = geojson.features.map(function (x) {
|
|
2535
|
+
return {
|
|
2536
|
+
geom: x,
|
|
2537
|
+
extent: x.bbox,
|
|
2538
|
+
text: x.properties && x.properties.display_name,
|
|
2539
|
+
query: val,
|
|
2540
|
+
};
|
|
2541
|
+
});
|
|
2542
|
+
resolve(features);
|
|
2543
|
+
}
|
|
2544
|
+
catch (er) {
|
|
2545
|
+
reject(er);
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
xhr.onerror = function (er) {
|
|
2549
|
+
reject(er);
|
|
2550
|
+
};
|
|
2551
|
+
onCancel(function () {
|
|
2552
|
+
xhr.abort();
|
|
2553
|
+
});
|
|
2554
|
+
xhr.send();
|
|
2555
|
+
}).catch(function (er) {
|
|
2556
|
+
if (er.name === 'CancelError') ;
|
|
2557
|
+
throw er;
|
|
2558
|
+
});
|
|
2559
|
+
this._requests.push(request);
|
|
2560
|
+
return [4 /*yield*/, __await(request)];
|
|
2561
|
+
case 1:
|
|
2562
|
+
items = _a.sent();
|
|
2563
|
+
if (!items) return [3 /*break*/, 5];
|
|
2564
|
+
_loop_1 = function (i) {
|
|
2565
|
+
return __generator(this, function (_b) {
|
|
2566
|
+
switch (_b.label) {
|
|
2567
|
+
case 0:
|
|
2568
|
+
i.result = function () { return _this.result(i); };
|
|
2569
|
+
return [4 /*yield*/, __await(i)];
|
|
2570
|
+
case 1: return [4 /*yield*/, _b.sent()];
|
|
2571
|
+
case 2:
|
|
2572
|
+
_b.sent();
|
|
2573
|
+
return [2 /*return*/];
|
|
2574
|
+
}
|
|
2575
|
+
});
|
|
2187
2576
|
};
|
|
2188
|
-
|
|
2189
|
-
|
|
2577
|
+
_i = 0, items_1 = items;
|
|
2578
|
+
_a.label = 2;
|
|
2579
|
+
case 2:
|
|
2580
|
+
if (!(_i < items_1.length)) return [3 /*break*/, 5];
|
|
2581
|
+
i = items_1[_i];
|
|
2582
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
2583
|
+
case 3:
|
|
2584
|
+
_a.sent();
|
|
2585
|
+
_a.label = 4;
|
|
2586
|
+
case 4:
|
|
2587
|
+
_i++;
|
|
2588
|
+
return [3 /*break*/, 2];
|
|
2589
|
+
case 5: return [2 /*return*/];
|
|
2190
2590
|
}
|
|
2191
|
-
catch (er) {
|
|
2192
|
-
reject(er);
|
|
2193
|
-
}
|
|
2194
|
-
};
|
|
2195
|
-
xhr.onerror = (er) => {
|
|
2196
|
-
reject(er);
|
|
2197
|
-
};
|
|
2198
|
-
onCancel(() => {
|
|
2199
|
-
xhr.abort();
|
|
2200
2591
|
});
|
|
2201
|
-
xhr.send();
|
|
2202
|
-
}).catch((er) => {
|
|
2203
|
-
if (er.name === 'CancelError') ;
|
|
2204
|
-
throw er;
|
|
2205
2592
|
});
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
if (items) {
|
|
2209
|
-
for (const i of items) {
|
|
2210
|
-
i.result = () => this.result(i);
|
|
2211
|
-
yield i;
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
result(model) {
|
|
2593
|
+
};
|
|
2594
|
+
NominatimProvider.prototype.result = function (model) {
|
|
2216
2595
|
return CancelablePromise.resolve({
|
|
2217
2596
|
text: model.text,
|
|
2218
2597
|
extent: model.extent || [],
|
|
2219
2598
|
geom: model.geom,
|
|
2220
2599
|
});
|
|
2221
|
-
}
|
|
2222
|
-
|
|
2600
|
+
};
|
|
2601
|
+
return NominatimProvider;
|
|
2602
|
+
}(BaseProvider));
|
|
2223
2603
|
|
|
2224
2604
|
function create(options) {
|
|
2225
2605
|
return new Geocoder(options);
|