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