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