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