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