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