@nextgis/ngw-connector 1.11.10 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -3
- package/lib/index.d.ts +14 -5
- package/lib/ngw-connector.cjs.js +494 -313
- package/lib/ngw-connector.cjs.js.map +1 -1
- package/lib/ngw-connector.cjs.prod.js +1 -1
- package/lib/ngw-connector.cjs.prod.js.map +1 -1
- package/lib/ngw-connector.esm-browser.js +657 -460
- package/lib/ngw-connector.esm-browser.js.map +1 -1
- package/lib/ngw-connector.esm-browser.prod.js +15 -1
- package/lib/ngw-connector.esm-browser.prod.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.js +455 -291
- package/lib/ngw-connector.esm-bundler.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js +15 -1
- package/lib/ngw-connector.esm-bundler.prod.js.map +1 -1
- package/lib/ngw-connector.global.js +57 -30
- package/lib/ngw-connector.global.js.map +1 -1
- package/lib/ngw-connector.global.prod.js +1 -1
- package/lib/ngw-connector.global.prod.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,49 +1,145 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 1.13.2; author: NextGIS */
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import CancelablePromise from '@nextgis/cancelable-promise';
|
|
4
4
|
import { objectDeepEqual, defined, objectRemoveEmpty, fixUrlStr } from '@nextgis/utils';
|
|
5
5
|
import Cache from '@nextgis/cache';
|
|
6
6
|
|
|
7
|
+
/*! *****************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
|
+
|
|
23
|
+
var extendStatics = function(d, b) {
|
|
24
|
+
extendStatics = Object.setPrototypeOf ||
|
|
25
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
27
|
+
return extendStatics(d, b);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
if (typeof b !== "function" && b !== null)
|
|
32
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
+
extendStatics(d, b);
|
|
34
|
+
function __() { this.constructor = d; }
|
|
35
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var __assign = function() {
|
|
39
|
+
__assign = Object.assign || function __assign(t) {
|
|
40
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
41
|
+
s = arguments[i];
|
|
42
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
46
|
+
return __assign.apply(this, arguments);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
50
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
51
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
52
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
53
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
54
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
55
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function __generator(thisArg, body) {
|
|
60
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
61
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
62
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
63
|
+
function step(op) {
|
|
64
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
65
|
+
while (_) try {
|
|
66
|
+
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;
|
|
67
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
68
|
+
switch (op[0]) {
|
|
69
|
+
case 0: case 1: t = op; break;
|
|
70
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
71
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
72
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
73
|
+
default:
|
|
74
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
75
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
76
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
77
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
78
|
+
if (t[2]) _.ops.pop();
|
|
79
|
+
_.trys.pop(); continue;
|
|
80
|
+
}
|
|
81
|
+
op = body.call(thisArg, _);
|
|
82
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
83
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function __spreadArray(to, from, pack) {
|
|
88
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
89
|
+
if (ar || !(i in from)) {
|
|
90
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
91
|
+
ar[i] = from[i];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
95
|
+
}
|
|
96
|
+
|
|
7
97
|
/**
|
|
8
98
|
* Thrown when...
|
|
9
99
|
*/
|
|
10
|
-
class
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Object.setPrototypeOf(
|
|
100
|
+
var NetworkError = /** @class */ (function (_super) {
|
|
101
|
+
__extends(NetworkError, _super);
|
|
102
|
+
function NetworkError(url) {
|
|
103
|
+
var _this = _super.call(this) || this;
|
|
104
|
+
_this.name = 'NetworkError';
|
|
105
|
+
Object.setPrototypeOf(_this, NetworkError.prototype);
|
|
106
|
+
_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
|
|
107
|
+
return _this;
|
|
16
108
|
}
|
|
17
|
-
|
|
109
|
+
return NetworkError;
|
|
110
|
+
}(Error));
|
|
18
111
|
|
|
19
112
|
/**
|
|
20
113
|
* Thrown when...
|
|
21
114
|
*/
|
|
22
|
-
class
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
115
|
+
var NgwError = /** @class */ (function (_super) {
|
|
116
|
+
__extends(NgwError, _super);
|
|
117
|
+
function NgwError(er) {
|
|
118
|
+
var _this = _super.call(this) || this;
|
|
119
|
+
_this.name = 'NgwError';
|
|
120
|
+
Object.assign(_this, er);
|
|
121
|
+
Object.setPrototypeOf(_this, NgwError.prototype);
|
|
122
|
+
return _this;
|
|
29
123
|
}
|
|
30
|
-
|
|
124
|
+
return NgwError;
|
|
125
|
+
}(Error));
|
|
31
126
|
|
|
32
127
|
function isObject(val) {
|
|
33
128
|
return Object.prototype.toString.call(val) === '[object Object]';
|
|
34
129
|
}
|
|
35
130
|
|
|
36
|
-
|
|
131
|
+
var loadData;
|
|
37
132
|
// @ts-ignore
|
|
38
133
|
{
|
|
39
|
-
loadData = (url, callback, options
|
|
134
|
+
loadData = function (url, callback, options, error, onCancel) {
|
|
135
|
+
if (options === void 0) { options = {}; }
|
|
40
136
|
options.method = options.method || 'GET';
|
|
41
|
-
|
|
137
|
+
var xhr = new XMLHttpRequest();
|
|
42
138
|
xhr.open(options.method || 'GET', url, true); // true for asynchronous
|
|
43
139
|
if (options.responseType === 'blob') {
|
|
44
140
|
xhr.responseType = options.responseType;
|
|
45
141
|
}
|
|
46
|
-
|
|
142
|
+
var getResponseText = function () {
|
|
47
143
|
try {
|
|
48
144
|
return JSON.parse(xhr.responseText);
|
|
49
145
|
}
|
|
@@ -51,8 +147,9 @@ let loadData;
|
|
|
51
147
|
return xhr.responseText;
|
|
52
148
|
}
|
|
53
149
|
};
|
|
54
|
-
|
|
55
|
-
|
|
150
|
+
var processingResponse = function (forError) {
|
|
151
|
+
if (forError === void 0) { forError = false; }
|
|
152
|
+
var cb = forError ? error : callback;
|
|
56
153
|
if (options.responseType === 'blob') {
|
|
57
154
|
cb(xhr.response);
|
|
58
155
|
}
|
|
@@ -65,7 +162,7 @@ let loadData;
|
|
|
65
162
|
}
|
|
66
163
|
}
|
|
67
164
|
};
|
|
68
|
-
xhr.onload = ()
|
|
165
|
+
xhr.onload = function () {
|
|
69
166
|
if ([401, 403, 404, 422, 500].indexOf(xhr.status) !== -1) {
|
|
70
167
|
error(new NgwError(getResponseText()));
|
|
71
168
|
}
|
|
@@ -87,7 +184,7 @@ let loadData;
|
|
|
87
184
|
// error('request error');
|
|
88
185
|
// }
|
|
89
186
|
// };
|
|
90
|
-
xhr.onerror = (er)
|
|
187
|
+
xhr.onerror = function (er) {
|
|
91
188
|
if (xhr.status === 0) {
|
|
92
189
|
error(new NetworkError(url));
|
|
93
190
|
}
|
|
@@ -97,17 +194,17 @@ let loadData;
|
|
|
97
194
|
};
|
|
98
195
|
xhr.upload.onprogress = function (e) {
|
|
99
196
|
if (e.lengthComputable) {
|
|
100
|
-
|
|
197
|
+
var percentComplete = (e.loaded / e.total) * 100;
|
|
101
198
|
if (options.onProgress) {
|
|
102
199
|
options.onProgress(percentComplete, e);
|
|
103
200
|
}
|
|
104
201
|
// console.log(percentComplete + '% uploaded');
|
|
105
202
|
}
|
|
106
203
|
};
|
|
107
|
-
|
|
204
|
+
var headers = options.headers;
|
|
108
205
|
if (headers) {
|
|
109
|
-
for (
|
|
110
|
-
|
|
206
|
+
for (var h in headers) {
|
|
207
|
+
var header = headers[h];
|
|
111
208
|
if (typeof header === 'string') {
|
|
112
209
|
xhr.setRequestHeader(h, header);
|
|
113
210
|
}
|
|
@@ -116,12 +213,12 @@ let loadData;
|
|
|
116
213
|
if (options.withCredentials !== undefined) {
|
|
117
214
|
xhr.withCredentials = options.withCredentials;
|
|
118
215
|
}
|
|
119
|
-
|
|
216
|
+
var data;
|
|
120
217
|
if (options.file) {
|
|
121
218
|
data = new FormData();
|
|
122
219
|
data.append('file', options.file);
|
|
123
220
|
if (options.data) {
|
|
124
|
-
for (
|
|
221
|
+
for (var d in options.data) {
|
|
125
222
|
data.append(d, data[d]);
|
|
126
223
|
}
|
|
127
224
|
}
|
|
@@ -134,7 +231,7 @@ let loadData;
|
|
|
134
231
|
: null;
|
|
135
232
|
}
|
|
136
233
|
if (onCancel) {
|
|
137
|
-
onCancel(()
|
|
234
|
+
onCancel(function () {
|
|
138
235
|
xhr.abort();
|
|
139
236
|
});
|
|
140
237
|
}
|
|
@@ -143,10 +240,10 @@ let loadData;
|
|
|
143
240
|
}
|
|
144
241
|
|
|
145
242
|
// https://github.com/Leaflet/Leaflet/blob/b507e21c510b53cd704fb8d3f89bb46ea925c8eb/src/core/Util.js#L165
|
|
146
|
-
|
|
243
|
+
var templateRe = /\{ *([\w_-]+) *\}/g;
|
|
147
244
|
function template(str, data) {
|
|
148
|
-
return str.replace(templateRe, (s, key)
|
|
149
|
-
|
|
245
|
+
return str.replace(templateRe, function (s, key) {
|
|
246
|
+
var value = data[key];
|
|
150
247
|
if (value === undefined) {
|
|
151
248
|
throw new Error('No value provided for letiable ' + s);
|
|
152
249
|
}
|
|
@@ -160,33 +257,39 @@ function template(str, data) {
|
|
|
160
257
|
/**
|
|
161
258
|
* Thrown when ...
|
|
162
259
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
260
|
+
var ResourceNotFoundError = /** @class */ (function (_super) {
|
|
261
|
+
__extends(ResourceNotFoundError, _super);
|
|
262
|
+
function ResourceNotFoundError(obj) {
|
|
263
|
+
var _this = _super.call(this, obj) || this;
|
|
264
|
+
_this.name = 'ResourceNotFoundError';
|
|
265
|
+
_this.exception = 'nextgisweb.resource.exception.ResourceNotFound';
|
|
266
|
+
Object.setPrototypeOf(_this, ResourceNotFoundError.prototype);
|
|
267
|
+
return _this;
|
|
169
268
|
}
|
|
170
|
-
|
|
269
|
+
return ResourceNotFoundError;
|
|
270
|
+
}(NgwError));
|
|
171
271
|
|
|
172
272
|
/**
|
|
173
273
|
* Thrown when ...
|
|
174
274
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
275
|
+
var InsufficientPermissionsError = /** @class */ (function (_super) {
|
|
276
|
+
__extends(InsufficientPermissionsError, _super);
|
|
277
|
+
function InsufficientPermissionsError(obj) {
|
|
278
|
+
var _this = _super.call(this, obj) || this;
|
|
279
|
+
_this.name = 'InsufficientPermissionsError';
|
|
280
|
+
_this.exception = 'nextgisweb.core.exception.InsufficientPermissions';
|
|
281
|
+
Object.setPrototypeOf(_this, InsufficientPermissionsError.prototype);
|
|
282
|
+
return _this;
|
|
181
283
|
}
|
|
182
|
-
|
|
284
|
+
return InsufficientPermissionsError;
|
|
285
|
+
}(NgwError));
|
|
183
286
|
|
|
184
|
-
|
|
287
|
+
var CONNECTORS = [];
|
|
185
288
|
function addConnector(connector) {
|
|
186
289
|
CONNECTORS.push(connector);
|
|
187
290
|
}
|
|
188
291
|
function findConnector(options) {
|
|
189
|
-
return CONNECTORS.find((x)
|
|
292
|
+
return CONNECTORS.find(function (x) {
|
|
190
293
|
if (x.options.baseUrl === options.baseUrl) {
|
|
191
294
|
if (options.auth) {
|
|
192
295
|
if (x.options.auth) {
|
|
@@ -201,13 +304,13 @@ function findConnector(options) {
|
|
|
201
304
|
});
|
|
202
305
|
}
|
|
203
306
|
function removeConnector(connector) {
|
|
204
|
-
|
|
307
|
+
var index = CONNECTORS.indexOf(connector);
|
|
205
308
|
if (index !== -1) {
|
|
206
309
|
CONNECTORS.splice(index, 1);
|
|
207
310
|
}
|
|
208
311
|
}
|
|
209
312
|
|
|
210
|
-
|
|
313
|
+
var exclude = ['description'];
|
|
211
314
|
/**
|
|
212
315
|
* @remarks
|
|
213
316
|
* https://docs.nextgis.ru/docs_ngweb_dev/doc/developer/resource.html#search-resources
|
|
@@ -218,14 +321,16 @@ const exclude = ['description'];
|
|
|
218
321
|
*
|
|
219
322
|
* @param resource - Any property from NGW resource item
|
|
220
323
|
*/
|
|
221
|
-
function resourceToQuery(resource, prefix
|
|
324
|
+
function resourceToQuery(resource, prefix) {
|
|
325
|
+
if (prefix === void 0) { prefix = ''; }
|
|
222
326
|
prefix = prefix ? prefix + '__' : '';
|
|
223
|
-
|
|
224
|
-
for (
|
|
327
|
+
var query = {};
|
|
328
|
+
for (var _i = 0, _a = Object.entries(resource); _i < _a.length; _i++) {
|
|
329
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
225
330
|
if (exclude.indexOf(key) === -1) {
|
|
226
331
|
if (isObject(value)) {
|
|
227
332
|
if (key === 'owner_user') {
|
|
228
|
-
|
|
333
|
+
var children = resourceToQuery(value, key);
|
|
229
334
|
Object.assign(query, children);
|
|
230
335
|
}
|
|
231
336
|
else if (key === 'parent' && 'id' in value) {
|
|
@@ -244,8 +349,8 @@ function resourceCompare(res1, res2) {
|
|
|
244
349
|
return objectDeepEqual(res1, res2);
|
|
245
350
|
}
|
|
246
351
|
|
|
247
|
-
|
|
248
|
-
|
|
352
|
+
var ResourcesControl = /** @class */ (function () {
|
|
353
|
+
function ResourcesControl(connector) {
|
|
249
354
|
this.connector = connector;
|
|
250
355
|
this.cache = new Cache();
|
|
251
356
|
}
|
|
@@ -259,10 +364,11 @@ class ResourcesControl {
|
|
|
259
364
|
* @remarks
|
|
260
365
|
* Fetching resource would be cached to speed up next call
|
|
261
366
|
*/
|
|
262
|
-
getOne(resource, requestOptions) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
367
|
+
ResourcesControl.prototype.getOne = function (resource, requestOptions) {
|
|
368
|
+
var _this = this;
|
|
369
|
+
var cache = new Cache();
|
|
370
|
+
var forCache = {};
|
|
371
|
+
var opt = __assign(__assign({}, requestOptions), { cache: false });
|
|
266
372
|
if (typeof resource === 'string') {
|
|
267
373
|
forCache.keyname = resource;
|
|
268
374
|
}
|
|
@@ -270,30 +376,35 @@ class ResourcesControl {
|
|
|
270
376
|
forCache.id = resource;
|
|
271
377
|
}
|
|
272
378
|
else if (isObject(resource)) {
|
|
273
|
-
|
|
379
|
+
if (resource.id !== undefined) {
|
|
380
|
+
forCache.id = resource.id;
|
|
381
|
+
}
|
|
382
|
+
else if (resource.keyname) {
|
|
383
|
+
forCache.keyname = resource.keyname;
|
|
384
|
+
}
|
|
274
385
|
}
|
|
275
|
-
|
|
386
|
+
var makeRequest = function () {
|
|
276
387
|
if (typeof resource === 'string') {
|
|
277
|
-
return
|
|
388
|
+
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
278
389
|
}
|
|
279
390
|
else if (typeof resource === 'number') {
|
|
280
|
-
return
|
|
391
|
+
return _this._fetchResourceById(resource, opt);
|
|
281
392
|
}
|
|
282
393
|
else if (isObject(resource)) {
|
|
283
|
-
return
|
|
394
|
+
return _this._fetchResourceBy(resource, opt);
|
|
284
395
|
}
|
|
285
396
|
return CancelablePromise.resolve(undefined);
|
|
286
397
|
};
|
|
287
398
|
return cache.addFull('resource', makeRequest, forCache);
|
|
288
|
-
}
|
|
289
|
-
getOneOrFail(resource, requestOptions) {
|
|
290
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
399
|
+
};
|
|
400
|
+
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
401
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
291
402
|
if (res) {
|
|
292
403
|
return res;
|
|
293
404
|
}
|
|
294
405
|
throw new ResourceNotFoundError();
|
|
295
406
|
});
|
|
296
|
-
}
|
|
407
|
+
};
|
|
297
408
|
/**
|
|
298
409
|
* A fast way to retrieve resource ID for any resource definition.
|
|
299
410
|
* @param resource - Any available resource definition
|
|
@@ -304,19 +415,19 @@ class ResourcesControl {
|
|
|
304
415
|
* then this method will come in handy to facilitate the extraction of the identifier
|
|
305
416
|
* if the resource is specified through a keyname or other parameters.
|
|
306
417
|
*/
|
|
307
|
-
getId(resource, requestOptions) {
|
|
418
|
+
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
308
419
|
if (typeof resource === 'number') {
|
|
309
420
|
return CancelablePromise.resolve(resource);
|
|
310
421
|
}
|
|
311
422
|
else if (typeof resource === 'string' || isObject(resource)) {
|
|
312
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
423
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
313
424
|
if (res) {
|
|
314
425
|
return res.resource.id;
|
|
315
426
|
}
|
|
316
427
|
});
|
|
317
428
|
}
|
|
318
429
|
return CancelablePromise.resolve(undefined);
|
|
319
|
-
}
|
|
430
|
+
};
|
|
320
431
|
/**
|
|
321
432
|
* A fast way to retrieve resource ID for any resource definition.
|
|
322
433
|
* @param resource - Any available resource definition
|
|
@@ -325,33 +436,32 @@ class ResourcesControl {
|
|
|
325
436
|
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
326
437
|
* To not make one more checks if the resource is definitely exists
|
|
327
438
|
*/
|
|
328
|
-
getIdOrFail(resource, requestOptions) {
|
|
329
|
-
return this.getId(resource, requestOptions).then((resp)
|
|
439
|
+
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
440
|
+
return this.getId(resource, requestOptions).then(function (resp) {
|
|
330
441
|
if (resp === undefined) {
|
|
331
442
|
throw new Error();
|
|
332
443
|
}
|
|
333
444
|
return resp;
|
|
334
445
|
});
|
|
335
|
-
}
|
|
336
|
-
getMany(resource, requestOptions) {
|
|
337
|
-
|
|
446
|
+
};
|
|
447
|
+
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
448
|
+
var _this = this;
|
|
449
|
+
return this._resourceCacheFilter(resource).then(function (items) {
|
|
338
450
|
if (!items.length) {
|
|
339
|
-
|
|
451
|
+
var query = {};
|
|
340
452
|
if (resource.keyname) {
|
|
341
453
|
query.keyname = resource.keyname;
|
|
342
454
|
}
|
|
343
455
|
else {
|
|
344
456
|
Object.assign(query, resourceToQuery(resource));
|
|
345
457
|
}
|
|
346
|
-
return
|
|
347
|
-
.get('resource.search', requestOptions, {
|
|
348
|
-
|
|
349
|
-
...query,
|
|
350
|
-
})
|
|
351
|
-
.then((resources) => {
|
|
458
|
+
return _this.connector
|
|
459
|
+
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
460
|
+
.then(function (resources) {
|
|
352
461
|
if (resources) {
|
|
353
|
-
for (
|
|
354
|
-
|
|
462
|
+
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
463
|
+
var x = resources_1[_i];
|
|
464
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(x), {
|
|
355
465
|
id: x.resource.id,
|
|
356
466
|
});
|
|
357
467
|
}
|
|
@@ -361,97 +471,137 @@ class ResourcesControl {
|
|
|
361
471
|
}
|
|
362
472
|
return items;
|
|
363
473
|
});
|
|
364
|
-
}
|
|
365
|
-
getParent(resource, requestOptions) {
|
|
366
|
-
|
|
474
|
+
};
|
|
475
|
+
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
476
|
+
var _this = this;
|
|
477
|
+
return this.getOne(resource, requestOptions).then(function (child) {
|
|
367
478
|
if (child) {
|
|
368
|
-
return
|
|
479
|
+
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
369
480
|
}
|
|
370
481
|
return CancelablePromise.resolve(undefined);
|
|
371
482
|
});
|
|
372
|
-
}
|
|
373
|
-
getChildrenOf(resource, requestOptions) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
483
|
+
};
|
|
484
|
+
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
485
|
+
var _this = this;
|
|
486
|
+
return this.getIdOrFail(resource).then(function (parent) {
|
|
487
|
+
return _this._getChildrenOf(parent, requestOptions);
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
|
|
491
|
+
var _this = this;
|
|
492
|
+
if (_items === void 0) { _items = []; }
|
|
493
|
+
return this.connector
|
|
494
|
+
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
495
|
+
parent: parent,
|
|
496
|
+
})
|
|
497
|
+
.then(function (items) {
|
|
498
|
+
var recursivePromises = [];
|
|
499
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
500
|
+
var item = items_1[_i];
|
|
501
|
+
_this.cache.add('resource.item', CancelablePromise.resolve(item), {
|
|
502
|
+
id: item.resource.id,
|
|
503
|
+
});
|
|
504
|
+
_items.push(item);
|
|
505
|
+
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
506
|
+
recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
|
|
384
507
|
}
|
|
385
|
-
|
|
386
|
-
|
|
508
|
+
}
|
|
509
|
+
if (recursivePromises.length) {
|
|
510
|
+
return CancelablePromise.all(recursivePromises).then(function () {
|
|
511
|
+
return _items;
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
return _items;
|
|
387
515
|
});
|
|
388
|
-
}
|
|
389
|
-
update(resource, data) {
|
|
390
|
-
|
|
516
|
+
};
|
|
517
|
+
ResourcesControl.prototype.update = function (resource, data) {
|
|
518
|
+
var _this = this;
|
|
519
|
+
return this.getId(resource).then(function (id) {
|
|
391
520
|
if (id !== undefined) {
|
|
392
|
-
return
|
|
521
|
+
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
393
522
|
}
|
|
394
523
|
});
|
|
395
|
-
}
|
|
524
|
+
};
|
|
396
525
|
/**
|
|
397
526
|
* Fast way to delete resource from NGW and clean cache.
|
|
398
527
|
* @param resource - Resource definition
|
|
399
528
|
*/
|
|
400
|
-
delete(resource) {
|
|
401
|
-
|
|
529
|
+
ResourcesControl.prototype.delete = function (resource) {
|
|
530
|
+
var _this = this;
|
|
531
|
+
return this.getId(resource).then(function (id) {
|
|
402
532
|
if (id !== undefined) {
|
|
403
|
-
return
|
|
404
|
-
|
|
533
|
+
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
534
|
+
_this._cleanResourceItemCache(id);
|
|
405
535
|
return undefined;
|
|
406
536
|
});
|
|
407
537
|
}
|
|
408
538
|
});
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
539
|
+
};
|
|
540
|
+
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
541
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
542
|
+
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
543
|
+
return __generator(this, function (_b) {
|
|
544
|
+
switch (_b.label) {
|
|
545
|
+
case 0:
|
|
546
|
+
all = this.cache.all();
|
|
547
|
+
toDelete = [];
|
|
548
|
+
_i = 0, all_1 = all;
|
|
549
|
+
_b.label = 1;
|
|
550
|
+
case 1:
|
|
551
|
+
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
552
|
+
c = all_1[_i];
|
|
553
|
+
cid = c.options && c.options.id;
|
|
554
|
+
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
555
|
+
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
556
|
+
if (cid === id) {
|
|
557
|
+
toDelete.push(c);
|
|
558
|
+
}
|
|
559
|
+
return [3 /*break*/, 4];
|
|
560
|
+
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
561
|
+
case 3:
|
|
562
|
+
rid = _b.sent();
|
|
563
|
+
if (rid === id) {
|
|
564
|
+
toDelete.push(c);
|
|
565
|
+
}
|
|
566
|
+
_b.label = 4;
|
|
567
|
+
case 4:
|
|
568
|
+
_i++;
|
|
569
|
+
return [3 /*break*/, 1];
|
|
570
|
+
case 5:
|
|
571
|
+
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
572
|
+
d = toDelete_1[_a];
|
|
573
|
+
this.cache.delete(d);
|
|
574
|
+
}
|
|
575
|
+
return [2 /*return*/];
|
|
426
576
|
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
};
|
|
580
|
+
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
581
|
+
var _this = this;
|
|
582
|
+
var promise = function () {
|
|
583
|
+
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
584
|
+
};
|
|
435
585
|
return this.cache
|
|
436
586
|
.add('resource.item', promise, {
|
|
437
|
-
id,
|
|
587
|
+
id: id,
|
|
438
588
|
})
|
|
439
|
-
.catch((er)
|
|
589
|
+
.catch(function (er) {
|
|
440
590
|
if (!(er instanceof ResourceNotFoundError)) {
|
|
441
591
|
throw er;
|
|
442
592
|
}
|
|
443
593
|
return undefined;
|
|
444
594
|
});
|
|
445
|
-
}
|
|
446
|
-
_fetchResourceBy(resource, requestOptions) {
|
|
447
|
-
return this.getMany(resource, requestOptions).then((resources)
|
|
595
|
+
};
|
|
596
|
+
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
597
|
+
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
448
598
|
return resources[0];
|
|
449
599
|
});
|
|
450
|
-
}
|
|
451
|
-
_resourceCacheFilter(resource) {
|
|
452
|
-
return CancelablePromise.all(this.cache.matchAll('resource.item')).then((resources)
|
|
453
|
-
|
|
454
|
-
resources.filter((x)
|
|
600
|
+
};
|
|
601
|
+
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
602
|
+
return CancelablePromise.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
603
|
+
var items = [];
|
|
604
|
+
resources.filter(function (x) {
|
|
455
605
|
if (x) {
|
|
456
606
|
// identical by uniq props
|
|
457
607
|
if (resource.keyname && x.resource.keyname) {
|
|
@@ -465,23 +615,24 @@ class ResourcesControl {
|
|
|
465
615
|
});
|
|
466
616
|
return items;
|
|
467
617
|
});
|
|
468
|
-
}
|
|
469
|
-
|
|
618
|
+
};
|
|
619
|
+
return ResourcesControl;
|
|
620
|
+
}());
|
|
470
621
|
|
|
471
622
|
function apiRequest(opt) {
|
|
472
|
-
|
|
473
|
-
return new CancelablePromise((resolve, reject)
|
|
623
|
+
var params = opt.params;
|
|
624
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
474
625
|
opt.connector
|
|
475
626
|
.connect()
|
|
476
|
-
.then((apiItems)
|
|
477
|
-
|
|
627
|
+
.then(function (apiItems) {
|
|
628
|
+
var apiItem = apiItems && apiItems[opt.name];
|
|
478
629
|
if (apiItem) {
|
|
479
|
-
apiItem = [
|
|
480
|
-
|
|
630
|
+
apiItem = __spreadArray([], apiItem, true);
|
|
631
|
+
var url = apiItem.shift();
|
|
481
632
|
if (apiItem.length) {
|
|
482
|
-
|
|
483
|
-
for (
|
|
484
|
-
|
|
633
|
+
var replaceParams = {};
|
|
634
|
+
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
635
|
+
var arg = apiItem[fry];
|
|
485
636
|
replaceParams[fry] = '{' + arg + '}';
|
|
486
637
|
if (params[arg] === undefined) {
|
|
487
638
|
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
@@ -493,21 +644,21 @@ function apiRequest(opt) {
|
|
|
493
644
|
}
|
|
494
645
|
// Transfer part of the parameters from `params` to the URL string
|
|
495
646
|
if (params) {
|
|
496
|
-
|
|
497
|
-
|
|
647
|
+
var paramArray_1 = [];
|
|
648
|
+
var paramList = params.paramList;
|
|
498
649
|
if (Array.isArray(paramList)) {
|
|
499
650
|
delete params.paramList;
|
|
500
|
-
paramList.forEach((x)
|
|
501
|
-
|
|
651
|
+
paramList.forEach(function (x) {
|
|
652
|
+
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
502
653
|
});
|
|
503
654
|
}
|
|
504
|
-
for (
|
|
655
|
+
for (var p in params) {
|
|
505
656
|
if (apiItem.indexOf(p) === -1) {
|
|
506
|
-
|
|
657
|
+
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
507
658
|
}
|
|
508
659
|
}
|
|
509
|
-
if (
|
|
510
|
-
url = url + '?' +
|
|
660
|
+
if (paramArray_1.length) {
|
|
661
|
+
url = url + '?' + paramArray_1.join('&');
|
|
511
662
|
}
|
|
512
663
|
}
|
|
513
664
|
if (url) {
|
|
@@ -521,20 +672,20 @@ function apiRequest(opt) {
|
|
|
521
672
|
resolve(undefined);
|
|
522
673
|
}
|
|
523
674
|
})
|
|
524
|
-
.catch((er)
|
|
675
|
+
.catch(function (er) {
|
|
525
676
|
reject(er);
|
|
526
677
|
});
|
|
527
678
|
});
|
|
528
679
|
}
|
|
529
680
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
681
|
+
var ID = 0;
|
|
682
|
+
var NgwConnector$1 = /** @class */ (function () {
|
|
683
|
+
function NgwConnector(options) {
|
|
533
684
|
this.options = options;
|
|
534
685
|
this.id = ID++;
|
|
535
686
|
this.emitter = new EventEmitter();
|
|
536
687
|
this.routeStr = '/api/component/pyramid/route';
|
|
537
|
-
|
|
688
|
+
var exist = findConnector(options);
|
|
538
689
|
if (exist) {
|
|
539
690
|
return exist;
|
|
540
691
|
}
|
|
@@ -546,19 +697,19 @@ class NgwConnector$1 {
|
|
|
546
697
|
addConnector(this);
|
|
547
698
|
}
|
|
548
699
|
}
|
|
549
|
-
|
|
700
|
+
NgwConnector.create = function (options) {
|
|
550
701
|
return new this(options);
|
|
551
|
-
}
|
|
702
|
+
};
|
|
552
703
|
/**
|
|
553
704
|
* Fast way to specify the connection address to NextGIS Web.
|
|
554
705
|
* The current connection will be severed.
|
|
555
706
|
* @param baseUrl - NGW url
|
|
556
707
|
*/
|
|
557
|
-
setNgw(baseUrl) {
|
|
708
|
+
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
558
709
|
this.logout();
|
|
559
710
|
this.options.baseUrl = baseUrl;
|
|
560
711
|
addConnector(this);
|
|
561
|
-
}
|
|
712
|
+
};
|
|
562
713
|
/**
|
|
563
714
|
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
564
715
|
* @remarks
|
|
@@ -572,101 +723,105 @@ class NgwConnector$1 {
|
|
|
572
723
|
* .catch((er) => console.log('Connection problem', er));
|
|
573
724
|
* ```
|
|
574
725
|
*/
|
|
575
|
-
connect() {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
reject(er);
|
|
586
|
-
});
|
|
587
|
-
};
|
|
588
|
-
if (auth) {
|
|
589
|
-
const { login, password } = auth;
|
|
590
|
-
if (login && password) {
|
|
591
|
-
return this.getUserInfo({ login, password })
|
|
592
|
-
.then(() => {
|
|
593
|
-
makeQuery();
|
|
726
|
+
NgwConnector.prototype.connect = function () {
|
|
727
|
+
var _this = this;
|
|
728
|
+
var cache = new Cache();
|
|
729
|
+
var auth = this.options.auth;
|
|
730
|
+
var makeConnect = function () {
|
|
731
|
+
return new CancelablePromise(function (resolve, reject) {
|
|
732
|
+
var makeQuery = function () {
|
|
733
|
+
return _this.makeQuery(_this.routeStr, {}, {})
|
|
734
|
+
.then(function (route) {
|
|
735
|
+
resolve(route);
|
|
594
736
|
})
|
|
595
|
-
.catch((er)
|
|
737
|
+
.catch(function (er) {
|
|
738
|
+
reject(er);
|
|
739
|
+
});
|
|
740
|
+
};
|
|
741
|
+
if (auth) {
|
|
742
|
+
var login = auth.login, password = auth.password;
|
|
743
|
+
if (login && password) {
|
|
744
|
+
return _this.getUserInfo({ login: login, password: password })
|
|
745
|
+
.then(function () {
|
|
746
|
+
makeQuery();
|
|
747
|
+
})
|
|
748
|
+
.catch(function (er) { return reject(er); });
|
|
749
|
+
}
|
|
596
750
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
751
|
+
return makeQuery();
|
|
752
|
+
});
|
|
753
|
+
};
|
|
600
754
|
return cache.add('route', makeConnect, {
|
|
601
755
|
id: this.id,
|
|
602
|
-
auth,
|
|
756
|
+
auth: auth,
|
|
603
757
|
baseUrl: this.options.baseUrl,
|
|
604
758
|
});
|
|
605
|
-
}
|
|
759
|
+
};
|
|
606
760
|
/**
|
|
607
761
|
* Quick way to change NextGIS Web user.
|
|
608
762
|
* @param credentials - New user credentials
|
|
609
763
|
*/
|
|
610
|
-
login(credentials) {
|
|
764
|
+
NgwConnector.prototype.login = function (credentials) {
|
|
611
765
|
this.logout();
|
|
612
766
|
addConnector(this);
|
|
613
767
|
return this.getUserInfo(credentials);
|
|
614
|
-
}
|
|
768
|
+
};
|
|
615
769
|
/**
|
|
616
770
|
* Disconnecting a user. Aborting all current requests
|
|
617
771
|
*/
|
|
618
|
-
logout() {
|
|
772
|
+
NgwConnector.prototype.logout = function () {
|
|
619
773
|
removeConnector(this);
|
|
620
774
|
this.options.auth = undefined;
|
|
621
775
|
this.user = undefined;
|
|
622
776
|
this.emitter.emit('logout');
|
|
623
777
|
this.resources.cache.clean();
|
|
624
|
-
}
|
|
625
|
-
getUserInfo(credentials) {
|
|
778
|
+
};
|
|
779
|
+
NgwConnector.prototype.getUserInfo = function (credentials) {
|
|
780
|
+
var _this = this;
|
|
626
781
|
if (this.user && this.user.id) {
|
|
627
782
|
return CancelablePromise.resolve(this.user);
|
|
628
783
|
}
|
|
629
784
|
if (credentials) {
|
|
630
785
|
this.options.auth = credentials;
|
|
631
786
|
}
|
|
632
|
-
|
|
787
|
+
var options = {
|
|
633
788
|
headers: this.getAuthorizationHeaders(credentials),
|
|
634
789
|
// withCredentials: true
|
|
635
790
|
};
|
|
636
791
|
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
637
792
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
638
|
-
.then((data)
|
|
639
|
-
|
|
640
|
-
|
|
793
|
+
.then(function (data) {
|
|
794
|
+
_this.user = data;
|
|
795
|
+
_this.emitter.emit('login', data);
|
|
641
796
|
return data;
|
|
642
797
|
})
|
|
643
|
-
.catch((er)
|
|
644
|
-
|
|
798
|
+
.catch(function (er) {
|
|
799
|
+
_this.emitter.emit('login:error', er);
|
|
645
800
|
throw er;
|
|
646
801
|
});
|
|
647
|
-
}
|
|
802
|
+
};
|
|
648
803
|
/**
|
|
649
804
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
650
805
|
*/
|
|
651
|
-
getAuthorizationHeaders(credentials) {
|
|
652
|
-
|
|
806
|
+
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
807
|
+
var client = this.makeClientId(credentials);
|
|
653
808
|
if (client) {
|
|
654
809
|
return {
|
|
655
810
|
Authorization: 'Basic ' + client,
|
|
656
811
|
};
|
|
657
812
|
}
|
|
658
|
-
}
|
|
659
|
-
makeClientId(credentials) {
|
|
813
|
+
};
|
|
814
|
+
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
660
815
|
credentials = credentials || this.options.auth;
|
|
661
816
|
if (credentials) {
|
|
662
|
-
|
|
663
|
-
|
|
817
|
+
var login = credentials.login, password = credentials.password;
|
|
818
|
+
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
664
819
|
// @ts-ignore
|
|
665
820
|
{
|
|
666
821
|
return window.btoa(str);
|
|
667
822
|
}
|
|
668
823
|
}
|
|
669
|
-
}
|
|
824
|
+
};
|
|
670
825
|
/**
|
|
671
826
|
* Send request to NGW api router.
|
|
672
827
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -696,25 +851,27 @@ class NgwConnector$1 {
|
|
|
696
851
|
*
|
|
697
852
|
* ```
|
|
698
853
|
*/
|
|
699
|
-
apiRequest(name, params_
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
854
|
+
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
855
|
+
var _this = this;
|
|
856
|
+
if (params_ === void 0) { params_ = {}; }
|
|
857
|
+
if (requestOptions === void 0) { requestOptions = {}; }
|
|
858
|
+
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
859
|
+
var params = objectRemoveEmpty(params_);
|
|
860
|
+
var makeApiRequest = function () {
|
|
861
|
+
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
862
|
+
};
|
|
703
863
|
if (requestOptions.cache && method === 'GET') {
|
|
704
|
-
|
|
705
|
-
return cache.add(name, makeApiRequest, {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
auth: this.options.auth,
|
|
713
|
-
}),
|
|
714
|
-
});
|
|
864
|
+
var cache = new Cache();
|
|
865
|
+
return cache.add(name, makeApiRequest, __assign({ params: params }, objectRemoveEmpty({
|
|
866
|
+
headers: headers,
|
|
867
|
+
withCredentials: withCredentials,
|
|
868
|
+
responseType: responseType,
|
|
869
|
+
baseUrl: this.options.baseUrl,
|
|
870
|
+
auth: this.options.auth,
|
|
871
|
+
})));
|
|
715
872
|
}
|
|
716
873
|
return makeApiRequest();
|
|
717
|
-
}
|
|
874
|
+
};
|
|
718
875
|
/**
|
|
719
876
|
* Shortcut method for send POST request to NGW.
|
|
720
877
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -728,62 +885,63 @@ class NgwConnector$1 {
|
|
|
728
885
|
* .catch((error) => console.warn(error));
|
|
729
886
|
* ```
|
|
730
887
|
*/
|
|
731
|
-
post(name, options, params) {
|
|
888
|
+
NgwConnector.prototype.post = function (name, options, params) {
|
|
732
889
|
options = options || {};
|
|
733
890
|
options.method = 'POST';
|
|
734
891
|
return this.apiRequest(name, params, options);
|
|
735
|
-
}
|
|
892
|
+
};
|
|
736
893
|
/**
|
|
737
894
|
* Shortcut method for send GET request to NGW.
|
|
738
895
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
739
896
|
* @param options - Request options
|
|
740
897
|
* @param params - Request item params or query params
|
|
741
898
|
*/
|
|
742
|
-
get(name, options, params) {
|
|
899
|
+
NgwConnector.prototype.get = function (name, options, params) {
|
|
743
900
|
options = options || {};
|
|
744
901
|
options.method = 'GET';
|
|
745
902
|
return this.apiRequest(name, params, options);
|
|
746
|
-
}
|
|
903
|
+
};
|
|
747
904
|
/**
|
|
748
905
|
* Shortcut method for send PATCH request to NGW.
|
|
749
906
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
750
907
|
* @param options - Request options
|
|
751
908
|
* @param params - Request item params or query params
|
|
752
909
|
*/
|
|
753
|
-
patch(name, options, params) {
|
|
910
|
+
NgwConnector.prototype.patch = function (name, options, params) {
|
|
754
911
|
options = options || {};
|
|
755
912
|
options.method = 'PATCH';
|
|
756
913
|
return this.apiRequest(name, params, options);
|
|
757
|
-
}
|
|
914
|
+
};
|
|
758
915
|
/**
|
|
759
916
|
* Shortcut method for send PUT request to NGW.
|
|
760
917
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
761
918
|
* @param options - Request options
|
|
762
919
|
* @param params - Request item params or query params
|
|
763
920
|
*/
|
|
764
|
-
put(name, options, params) {
|
|
921
|
+
NgwConnector.prototype.put = function (name, options, params) {
|
|
765
922
|
options = options || {};
|
|
766
923
|
options.method = 'PUT';
|
|
767
924
|
return this.apiRequest(name, params, options);
|
|
768
|
-
}
|
|
925
|
+
};
|
|
769
926
|
/**
|
|
770
927
|
* Shortcut method for send DELETE request to NGW.
|
|
771
928
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
772
929
|
* @param options - Request options
|
|
773
930
|
* @param params - Request item params or query params
|
|
774
931
|
*/
|
|
775
|
-
delete(name, options, params) {
|
|
932
|
+
NgwConnector.prototype.delete = function (name, options, params) {
|
|
776
933
|
options = options || {};
|
|
777
934
|
options.method = 'DELETE';
|
|
778
935
|
return this.apiRequest(name, params, options);
|
|
779
|
-
}
|
|
936
|
+
};
|
|
780
937
|
/**
|
|
781
938
|
* Send request to NGW.
|
|
782
939
|
* @param url - URL address to NGW
|
|
783
940
|
* @param params - Query params
|
|
784
941
|
* @param options - Request options
|
|
785
942
|
*/
|
|
786
|
-
makeQuery(url, params, options
|
|
943
|
+
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
944
|
+
if (options === void 0) { options = {}; }
|
|
787
945
|
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
788
946
|
if (url) {
|
|
789
947
|
if (params) {
|
|
@@ -796,112 +954,117 @@ class NgwConnector$1 {
|
|
|
796
954
|
else {
|
|
797
955
|
throw new Error('Empty `url` not allowed');
|
|
798
956
|
}
|
|
799
|
-
}
|
|
957
|
+
};
|
|
800
958
|
// -------------------------------------------------------------------------
|
|
801
959
|
// Resource Methods
|
|
802
960
|
// -------------------------------------------------------------------------
|
|
803
961
|
/**
|
|
804
962
|
* {@inheritDoc ResourcesControl.getOne}
|
|
805
963
|
*/
|
|
806
|
-
getResource(resource, requestOptions) {
|
|
964
|
+
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
807
965
|
return this.resources.getOne(resource, requestOptions);
|
|
808
|
-
}
|
|
966
|
+
};
|
|
809
967
|
/**
|
|
810
968
|
* {@inheritDoc ResourcesControl.getOneOrFail}
|
|
811
969
|
*/
|
|
812
|
-
getResourceOrFail(resource, requestOptions) {
|
|
970
|
+
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
813
971
|
return this.resources.getOneOrFail(resource, requestOptions);
|
|
814
|
-
}
|
|
972
|
+
};
|
|
815
973
|
/**
|
|
816
974
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
817
975
|
*/
|
|
818
|
-
getResourceBy(resource) {
|
|
976
|
+
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
819
977
|
return this.resources.getOne(resource);
|
|
820
|
-
}
|
|
978
|
+
};
|
|
821
979
|
/**
|
|
822
980
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
823
981
|
*/
|
|
824
|
-
getResourceByKeyname(keyname) {
|
|
982
|
+
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
825
983
|
return this.resources.getOne(keyname);
|
|
826
|
-
}
|
|
984
|
+
};
|
|
827
985
|
/**
|
|
828
986
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
829
987
|
*/
|
|
830
|
-
getResourceById(id) {
|
|
988
|
+
NgwConnector.prototype.getResourceById = function (id) {
|
|
831
989
|
return this.resources.getOne(id);
|
|
832
|
-
}
|
|
990
|
+
};
|
|
833
991
|
/**
|
|
834
992
|
* {@inheritDoc ResourcesControl.getId}
|
|
835
993
|
*/
|
|
836
|
-
getResourceId(resource, requestOptions) {
|
|
994
|
+
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
837
995
|
return this.resources.getId(resource, requestOptions);
|
|
838
|
-
}
|
|
996
|
+
};
|
|
839
997
|
/**
|
|
840
998
|
* {@inheritDoc ResourcesControl.getIdOrFail}
|
|
841
999
|
*/
|
|
842
|
-
getResourceIdOrFail(resource, requestOptions) {
|
|
1000
|
+
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
843
1001
|
return this.resources.getIdOrFail(resource, requestOptions);
|
|
844
|
-
}
|
|
1002
|
+
};
|
|
845
1003
|
/**
|
|
846
1004
|
* {@inheritDoc ResourcesControl.getMany}
|
|
847
1005
|
*/
|
|
848
|
-
getResourcesBy(resource, requestOptions) {
|
|
1006
|
+
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
849
1007
|
return this.resources.getMany(resource, requestOptions);
|
|
850
|
-
}
|
|
1008
|
+
};
|
|
851
1009
|
/**
|
|
852
1010
|
* {@inheritDoc ResourcesControl.getParent}
|
|
853
1011
|
*/
|
|
854
|
-
getResourceParent(resource, requestOptions) {
|
|
1012
|
+
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
855
1013
|
return this.resources.getParent(resource, requestOptions);
|
|
856
|
-
}
|
|
1014
|
+
};
|
|
857
1015
|
/**
|
|
858
1016
|
* {@inheritDoc ResourcesControl.getChildrenOf}
|
|
859
1017
|
*/
|
|
860
|
-
getResourceChildren(resource, requestOptions) {
|
|
1018
|
+
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
861
1019
|
return this.resources.getChildrenOf(resource, requestOptions);
|
|
862
|
-
}
|
|
1020
|
+
};
|
|
863
1021
|
/**
|
|
864
1022
|
* {@inheritDoc ResourcesControl.update}
|
|
865
1023
|
*/
|
|
866
|
-
updateResource(resource, data) {
|
|
1024
|
+
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
867
1025
|
return this.resources.update(resource, data);
|
|
868
|
-
}
|
|
1026
|
+
};
|
|
869
1027
|
/**
|
|
870
1028
|
* {@inheritDoc ResourcesControl.delete}
|
|
871
1029
|
*/
|
|
872
|
-
deleteResource(resource) {
|
|
1030
|
+
NgwConnector.prototype.deleteResource = function (resource) {
|
|
873
1031
|
return this.resources.delete(resource);
|
|
874
|
-
}
|
|
1032
|
+
};
|
|
875
1033
|
/**
|
|
876
1034
|
* @internal
|
|
877
1035
|
*/
|
|
878
|
-
_loadData(url, options) {
|
|
1036
|
+
NgwConnector.prototype._loadData = function (url, options) {
|
|
1037
|
+
var _this = this;
|
|
879
1038
|
options.responseType = options.responseType || 'json';
|
|
880
|
-
|
|
881
|
-
if (
|
|
1039
|
+
var request = new CancelablePromise(function (resolve, reject, onCancel) {
|
|
1040
|
+
if (_this.user) {
|
|
882
1041
|
options = options || {};
|
|
883
1042
|
// options.withCredentials = true;
|
|
884
|
-
options.headers = {
|
|
885
|
-
...this.getAuthorizationHeaders(),
|
|
886
|
-
...options.headers,
|
|
887
|
-
};
|
|
1043
|
+
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
888
1044
|
}
|
|
889
1045
|
loadData(url, resolve, options, reject, onCancel);
|
|
890
|
-
}).catch((httpError)
|
|
1046
|
+
}).catch(function (httpError) {
|
|
891
1047
|
if (httpError instanceof CancelablePromise.CancelError) ;
|
|
892
1048
|
else {
|
|
893
1049
|
// @ts-ignore
|
|
894
1050
|
if ((process.env.NODE_ENV !== 'production')) {
|
|
895
1051
|
console.warn('DEV WARN', httpError);
|
|
896
1052
|
}
|
|
897
|
-
|
|
1053
|
+
var er = _this._handleHttpError(httpError);
|
|
898
1054
|
if (er) {
|
|
899
1055
|
throw er;
|
|
900
1056
|
}
|
|
901
1057
|
}
|
|
902
1058
|
});
|
|
903
|
-
|
|
904
|
-
|
|
1059
|
+
if (options.signal &&
|
|
1060
|
+
typeof options.signal.addEventListener === 'function') {
|
|
1061
|
+
options.signal.addEventListener('abort', function () {
|
|
1062
|
+
request.cancel();
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
return request;
|
|
1066
|
+
};
|
|
1067
|
+
NgwConnector.prototype._handleHttpError = function (er) {
|
|
905
1068
|
if (er) {
|
|
906
1069
|
if (er instanceof NgwError) {
|
|
907
1070
|
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
@@ -913,12 +1076,13 @@ class NgwConnector$1 {
|
|
|
913
1076
|
}
|
|
914
1077
|
}
|
|
915
1078
|
return er;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1079
|
+
};
|
|
1080
|
+
NgwConnector.errors = {
|
|
1081
|
+
NgwError: NgwError,
|
|
1082
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
1083
|
+
};
|
|
1084
|
+
return NgwConnector;
|
|
1085
|
+
}());
|
|
922
1086
|
|
|
923
1087
|
/**
|
|
924
1088
|
* A lightweight HTTP client optimized for use with {@link http://docs.nextgis.ru/docs_ngweb_dev/doc/developer/toc.html | NextGIS Web} API
|