@nextgis/ngw-connector 1.11.10 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/ngw-connector.cjs.js +448 -305
- 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 +624 -454
- 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 +422 -285
- 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 +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.0; 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
|
}
|
|
@@ -281,28 +393,28 @@ class ResourcesControl {
|
|
|
281
393
|
else if (isObject(resource)) {
|
|
282
394
|
forCache.id = resource.id;
|
|
283
395
|
}
|
|
284
|
-
|
|
396
|
+
var makeRequest = function () {
|
|
285
397
|
if (typeof resource === 'string') {
|
|
286
|
-
return
|
|
398
|
+
return _this._fetchResourceBy({ keyname: resource }, opt);
|
|
287
399
|
}
|
|
288
400
|
else if (typeof resource === 'number') {
|
|
289
|
-
return
|
|
401
|
+
return _this._fetchResourceById(resource, opt);
|
|
290
402
|
}
|
|
291
403
|
else if (isObject(resource)) {
|
|
292
|
-
return
|
|
404
|
+
return _this._fetchResourceBy(resource, opt);
|
|
293
405
|
}
|
|
294
406
|
return CancelablePromise__default.resolve(undefined);
|
|
295
407
|
};
|
|
296
408
|
return cache.addFull('resource', makeRequest, forCache);
|
|
297
|
-
}
|
|
298
|
-
getOneOrFail(resource, requestOptions) {
|
|
299
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
409
|
+
};
|
|
410
|
+
ResourcesControl.prototype.getOneOrFail = function (resource, requestOptions) {
|
|
411
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
300
412
|
if (res) {
|
|
301
413
|
return res;
|
|
302
414
|
}
|
|
303
415
|
throw new ResourceNotFoundError();
|
|
304
416
|
});
|
|
305
|
-
}
|
|
417
|
+
};
|
|
306
418
|
/**
|
|
307
419
|
* A fast way to retrieve resource ID for any resource definition.
|
|
308
420
|
* @param resource - Any available resource definition
|
|
@@ -313,19 +425,19 @@ class ResourcesControl {
|
|
|
313
425
|
* then this method will come in handy to facilitate the extraction of the identifier
|
|
314
426
|
* if the resource is specified through a keyname or other parameters.
|
|
315
427
|
*/
|
|
316
|
-
getId(resource, requestOptions) {
|
|
428
|
+
ResourcesControl.prototype.getId = function (resource, requestOptions) {
|
|
317
429
|
if (typeof resource === 'number') {
|
|
318
430
|
return CancelablePromise__default.resolve(resource);
|
|
319
431
|
}
|
|
320
432
|
else if (typeof resource === 'string' || isObject(resource)) {
|
|
321
|
-
return this.getOne(resource, requestOptions).then((res)
|
|
433
|
+
return this.getOne(resource, requestOptions).then(function (res) {
|
|
322
434
|
if (res) {
|
|
323
435
|
return res.resource.id;
|
|
324
436
|
}
|
|
325
437
|
});
|
|
326
438
|
}
|
|
327
439
|
return CancelablePromise__default.resolve(undefined);
|
|
328
|
-
}
|
|
440
|
+
};
|
|
329
441
|
/**
|
|
330
442
|
* A fast way to retrieve resource ID for any resource definition.
|
|
331
443
|
* @param resource - Any available resource definition
|
|
@@ -334,33 +446,32 @@ class ResourcesControl {
|
|
|
334
446
|
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
335
447
|
* To not make one more checks if the resource is definitely exists
|
|
336
448
|
*/
|
|
337
|
-
getIdOrFail(resource, requestOptions) {
|
|
338
|
-
return this.getId(resource, requestOptions).then((resp)
|
|
449
|
+
ResourcesControl.prototype.getIdOrFail = function (resource, requestOptions) {
|
|
450
|
+
return this.getId(resource, requestOptions).then(function (resp) {
|
|
339
451
|
if (resp === undefined) {
|
|
340
452
|
throw new Error();
|
|
341
453
|
}
|
|
342
454
|
return resp;
|
|
343
455
|
});
|
|
344
|
-
}
|
|
345
|
-
getMany(resource, requestOptions) {
|
|
346
|
-
|
|
456
|
+
};
|
|
457
|
+
ResourcesControl.prototype.getMany = function (resource, requestOptions) {
|
|
458
|
+
var _this = this;
|
|
459
|
+
return this._resourceCacheFilter(resource).then(function (items) {
|
|
347
460
|
if (!items.length) {
|
|
348
|
-
|
|
461
|
+
var query = {};
|
|
349
462
|
if (resource.keyname) {
|
|
350
463
|
query.keyname = resource.keyname;
|
|
351
464
|
}
|
|
352
465
|
else {
|
|
353
466
|
Object.assign(query, resourceToQuery(resource));
|
|
354
467
|
}
|
|
355
|
-
return
|
|
356
|
-
.get('resource.search', requestOptions, {
|
|
357
|
-
|
|
358
|
-
...query,
|
|
359
|
-
})
|
|
360
|
-
.then((resources) => {
|
|
468
|
+
return _this.connector
|
|
469
|
+
.get('resource.search', requestOptions, __assign({ serialization: 'full' }, query))
|
|
470
|
+
.then(function (resources) {
|
|
361
471
|
if (resources) {
|
|
362
|
-
for (
|
|
363
|
-
|
|
472
|
+
for (var _i = 0, resources_1 = resources; _i < resources_1.length; _i++) {
|
|
473
|
+
var x = resources_1[_i];
|
|
474
|
+
_this.cache.add('resource.item', CancelablePromise__default.resolve(x), {
|
|
364
475
|
id: x.resource.id,
|
|
365
476
|
});
|
|
366
477
|
}
|
|
@@ -370,97 +481,122 @@ class ResourcesControl {
|
|
|
370
481
|
}
|
|
371
482
|
return items;
|
|
372
483
|
});
|
|
373
|
-
}
|
|
374
|
-
getParent(resource, requestOptions) {
|
|
375
|
-
|
|
484
|
+
};
|
|
485
|
+
ResourcesControl.prototype.getParent = function (resource, requestOptions) {
|
|
486
|
+
var _this = this;
|
|
487
|
+
return this.getOne(resource, requestOptions).then(function (child) {
|
|
376
488
|
if (child) {
|
|
377
|
-
return
|
|
489
|
+
return _this.getOne(child.resource.parent.id, requestOptions);
|
|
378
490
|
}
|
|
379
491
|
return CancelablePromise__default.resolve(undefined);
|
|
380
492
|
});
|
|
381
|
-
}
|
|
382
|
-
getChildrenOf(resource, requestOptions) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
493
|
+
};
|
|
494
|
+
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
495
|
+
var _this = this;
|
|
496
|
+
return this.getId(resource).then(function (parent) {
|
|
497
|
+
return _this.connector
|
|
498
|
+
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
499
|
+
parent: parent,
|
|
387
500
|
})
|
|
388
|
-
.then((items)
|
|
389
|
-
for (
|
|
390
|
-
|
|
501
|
+
.then(function (items) {
|
|
502
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
503
|
+
var i = items_1[_i];
|
|
504
|
+
_this.cache.add('resource.item', CancelablePromise__default.resolve(i), {
|
|
391
505
|
id: i.resource.id,
|
|
392
506
|
});
|
|
393
507
|
}
|
|
394
508
|
return items;
|
|
395
509
|
});
|
|
396
510
|
});
|
|
397
|
-
}
|
|
398
|
-
update(resource, data) {
|
|
399
|
-
|
|
511
|
+
};
|
|
512
|
+
ResourcesControl.prototype.update = function (resource, data) {
|
|
513
|
+
var _this = this;
|
|
514
|
+
return this.getId(resource).then(function (id) {
|
|
400
515
|
if (id !== undefined) {
|
|
401
|
-
return
|
|
516
|
+
return _this.connector.put('resource.item', { data: data }, { id: id });
|
|
402
517
|
}
|
|
403
518
|
});
|
|
404
|
-
}
|
|
519
|
+
};
|
|
405
520
|
/**
|
|
406
521
|
* Fast way to delete resource from NGW and clean cache.
|
|
407
522
|
* @param resource - Resource definition
|
|
408
523
|
*/
|
|
409
|
-
delete(resource) {
|
|
410
|
-
|
|
524
|
+
ResourcesControl.prototype.delete = function (resource) {
|
|
525
|
+
var _this = this;
|
|
526
|
+
return this.getId(resource).then(function (id) {
|
|
411
527
|
if (id !== undefined) {
|
|
412
|
-
return
|
|
413
|
-
|
|
528
|
+
return _this.connector.delete('resource.item', null, { id: id }).then(function () {
|
|
529
|
+
_this._cleanResourceItemCache(id);
|
|
414
530
|
return undefined;
|
|
415
531
|
});
|
|
416
532
|
}
|
|
417
533
|
});
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
534
|
+
};
|
|
535
|
+
ResourcesControl.prototype._cleanResourceItemCache = function (id) {
|
|
536
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
537
|
+
var all, toDelete, _i, all_1, c, cid, rid, _a, toDelete_1, d;
|
|
538
|
+
return __generator(this, function (_b) {
|
|
539
|
+
switch (_b.label) {
|
|
540
|
+
case 0:
|
|
541
|
+
all = this.cache.all();
|
|
542
|
+
toDelete = [];
|
|
543
|
+
_i = 0, all_1 = all;
|
|
544
|
+
_b.label = 1;
|
|
545
|
+
case 1:
|
|
546
|
+
if (!(_i < all_1.length)) return [3 /*break*/, 5];
|
|
547
|
+
c = all_1[_i];
|
|
548
|
+
cid = c.options && c.options.id;
|
|
549
|
+
if (!(['resource.item', 'resource'].includes(c.key) && cid !== undefined)) return [3 /*break*/, 4];
|
|
550
|
+
if (!(typeof cid === 'number')) return [3 /*break*/, 2];
|
|
551
|
+
if (cid === id) {
|
|
552
|
+
toDelete.push(c);
|
|
553
|
+
}
|
|
554
|
+
return [3 /*break*/, 4];
|
|
555
|
+
case 2: return [4 /*yield*/, this.getId(cid)];
|
|
556
|
+
case 3:
|
|
557
|
+
rid = _b.sent();
|
|
558
|
+
if (rid === id) {
|
|
559
|
+
toDelete.push(c);
|
|
560
|
+
}
|
|
561
|
+
_b.label = 4;
|
|
562
|
+
case 4:
|
|
563
|
+
_i++;
|
|
564
|
+
return [3 /*break*/, 1];
|
|
565
|
+
case 5:
|
|
566
|
+
for (_a = 0, toDelete_1 = toDelete; _a < toDelete_1.length; _a++) {
|
|
567
|
+
d = toDelete_1[_a];
|
|
568
|
+
this.cache.delete(d);
|
|
569
|
+
}
|
|
570
|
+
return [2 /*return*/];
|
|
435
571
|
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
};
|
|
575
|
+
ResourcesControl.prototype._fetchResourceById = function (id, requestOptions) {
|
|
576
|
+
var _this = this;
|
|
577
|
+
var promise = function () {
|
|
578
|
+
return _this.connector.get('resource.item', requestOptions, { id: id });
|
|
579
|
+
};
|
|
444
580
|
return this.cache
|
|
445
581
|
.add('resource.item', promise, {
|
|
446
|
-
id,
|
|
582
|
+
id: id,
|
|
447
583
|
})
|
|
448
|
-
.catch((er)
|
|
584
|
+
.catch(function (er) {
|
|
449
585
|
if (!(er instanceof ResourceNotFoundError)) {
|
|
450
586
|
throw er;
|
|
451
587
|
}
|
|
452
588
|
return undefined;
|
|
453
589
|
});
|
|
454
|
-
}
|
|
455
|
-
_fetchResourceBy(resource, requestOptions) {
|
|
456
|
-
return this.getMany(resource, requestOptions).then((resources)
|
|
590
|
+
};
|
|
591
|
+
ResourcesControl.prototype._fetchResourceBy = function (resource, requestOptions) {
|
|
592
|
+
return this.getMany(resource, requestOptions).then(function (resources) {
|
|
457
593
|
return resources[0];
|
|
458
594
|
});
|
|
459
|
-
}
|
|
460
|
-
_resourceCacheFilter(resource) {
|
|
461
|
-
return CancelablePromise__default.all(this.cache.matchAll('resource.item')).then((resources)
|
|
462
|
-
|
|
463
|
-
resources.filter((x)
|
|
595
|
+
};
|
|
596
|
+
ResourcesControl.prototype._resourceCacheFilter = function (resource) {
|
|
597
|
+
return CancelablePromise__default.all(this.cache.matchAll('resource.item')).then(function (resources) {
|
|
598
|
+
var items = [];
|
|
599
|
+
resources.filter(function (x) {
|
|
464
600
|
if (x) {
|
|
465
601
|
// identical by uniq props
|
|
466
602
|
if (resource.keyname && x.resource.keyname) {
|
|
@@ -474,23 +610,24 @@ class ResourcesControl {
|
|
|
474
610
|
});
|
|
475
611
|
return items;
|
|
476
612
|
});
|
|
477
|
-
}
|
|
478
|
-
|
|
613
|
+
};
|
|
614
|
+
return ResourcesControl;
|
|
615
|
+
}());
|
|
479
616
|
|
|
480
617
|
function apiRequest(opt) {
|
|
481
|
-
|
|
482
|
-
return new CancelablePromise__default((resolve, reject)
|
|
618
|
+
var params = opt.params;
|
|
619
|
+
return new CancelablePromise__default(function (resolve, reject) {
|
|
483
620
|
opt.connector
|
|
484
621
|
.connect()
|
|
485
|
-
.then((apiItems)
|
|
486
|
-
|
|
622
|
+
.then(function (apiItems) {
|
|
623
|
+
var apiItem = apiItems && apiItems[opt.name];
|
|
487
624
|
if (apiItem) {
|
|
488
|
-
apiItem = [
|
|
489
|
-
|
|
625
|
+
apiItem = __spreadArray([], apiItem, true);
|
|
626
|
+
var url = apiItem.shift();
|
|
490
627
|
if (apiItem.length) {
|
|
491
|
-
|
|
492
|
-
for (
|
|
493
|
-
|
|
628
|
+
var replaceParams = {};
|
|
629
|
+
for (var fry = 0; fry < apiItem.length; fry++) {
|
|
630
|
+
var arg = apiItem[fry];
|
|
494
631
|
replaceParams[fry] = '{' + arg + '}';
|
|
495
632
|
if (params[arg] === undefined) {
|
|
496
633
|
throw new Error('`' + arg + '`' + ' url api argument is not specified');
|
|
@@ -502,21 +639,21 @@ function apiRequest(opt) {
|
|
|
502
639
|
}
|
|
503
640
|
// Transfer part of the parameters from `params` to the URL string
|
|
504
641
|
if (params) {
|
|
505
|
-
|
|
506
|
-
|
|
642
|
+
var paramArray_1 = [];
|
|
643
|
+
var paramList = params.paramList;
|
|
507
644
|
if (Array.isArray(paramList)) {
|
|
508
645
|
delete params.paramList;
|
|
509
|
-
paramList.forEach((x)
|
|
510
|
-
|
|
646
|
+
paramList.forEach(function (x) {
|
|
647
|
+
paramArray_1.push("".concat(x[0], "=").concat(x[1]));
|
|
511
648
|
});
|
|
512
649
|
}
|
|
513
|
-
for (
|
|
650
|
+
for (var p in params) {
|
|
514
651
|
if (apiItem.indexOf(p) === -1) {
|
|
515
|
-
|
|
652
|
+
paramArray_1.push("".concat(p, "=").concat(params[p]));
|
|
516
653
|
}
|
|
517
654
|
}
|
|
518
|
-
if (
|
|
519
|
-
url = url + '?' +
|
|
655
|
+
if (paramArray_1.length) {
|
|
656
|
+
url = url + '?' + paramArray_1.join('&');
|
|
520
657
|
}
|
|
521
658
|
}
|
|
522
659
|
if (url) {
|
|
@@ -530,20 +667,20 @@ function apiRequest(opt) {
|
|
|
530
667
|
resolve(undefined);
|
|
531
668
|
}
|
|
532
669
|
})
|
|
533
|
-
.catch((er)
|
|
670
|
+
.catch(function (er) {
|
|
534
671
|
reject(er);
|
|
535
672
|
});
|
|
536
673
|
});
|
|
537
674
|
}
|
|
538
675
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
676
|
+
var ID = 0;
|
|
677
|
+
var NgwConnector$1 = /** @class */ (function () {
|
|
678
|
+
function NgwConnector(options) {
|
|
542
679
|
this.options = options;
|
|
543
680
|
this.id = ID++;
|
|
544
681
|
this.emitter = new events.EventEmitter();
|
|
545
682
|
this.routeStr = '/api/component/pyramid/route';
|
|
546
|
-
|
|
683
|
+
var exist = findConnector(options);
|
|
547
684
|
if (exist) {
|
|
548
685
|
return exist;
|
|
549
686
|
}
|
|
@@ -555,19 +692,19 @@ class NgwConnector$1 {
|
|
|
555
692
|
addConnector(this);
|
|
556
693
|
}
|
|
557
694
|
}
|
|
558
|
-
|
|
695
|
+
NgwConnector.create = function (options) {
|
|
559
696
|
return new this(options);
|
|
560
|
-
}
|
|
697
|
+
};
|
|
561
698
|
/**
|
|
562
699
|
* Fast way to specify the connection address to NextGIS Web.
|
|
563
700
|
* The current connection will be severed.
|
|
564
701
|
* @param baseUrl - NGW url
|
|
565
702
|
*/
|
|
566
|
-
setNgw(baseUrl) {
|
|
703
|
+
NgwConnector.prototype.setNgw = function (baseUrl) {
|
|
567
704
|
this.logout();
|
|
568
705
|
this.options.baseUrl = baseUrl;
|
|
569
706
|
addConnector(this);
|
|
570
|
-
}
|
|
707
|
+
};
|
|
571
708
|
/**
|
|
572
709
|
* Establishing a connection with NextGIS Web to fulfill all other requests.
|
|
573
710
|
* @remarks
|
|
@@ -581,101 +718,105 @@ class NgwConnector$1 {
|
|
|
581
718
|
* .catch((er) => console.log('Connection problem', er));
|
|
582
719
|
* ```
|
|
583
720
|
*/
|
|
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();
|
|
721
|
+
NgwConnector.prototype.connect = function () {
|
|
722
|
+
var _this = this;
|
|
723
|
+
var cache = new Cache__default();
|
|
724
|
+
var auth = this.options.auth;
|
|
725
|
+
var makeConnect = function () {
|
|
726
|
+
return new CancelablePromise__default(function (resolve, reject) {
|
|
727
|
+
var makeQuery = function () {
|
|
728
|
+
return _this.makeQuery(_this.routeStr, {}, {})
|
|
729
|
+
.then(function (route) {
|
|
730
|
+
resolve(route);
|
|
603
731
|
})
|
|
604
|
-
.catch((er)
|
|
732
|
+
.catch(function (er) {
|
|
733
|
+
reject(er);
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
if (auth) {
|
|
737
|
+
var login = auth.login, password = auth.password;
|
|
738
|
+
if (login && password) {
|
|
739
|
+
return _this.getUserInfo({ login: login, password: password })
|
|
740
|
+
.then(function () {
|
|
741
|
+
makeQuery();
|
|
742
|
+
})
|
|
743
|
+
.catch(function (er) { return reject(er); });
|
|
744
|
+
}
|
|
605
745
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
746
|
+
return makeQuery();
|
|
747
|
+
});
|
|
748
|
+
};
|
|
609
749
|
return cache.add('route', makeConnect, {
|
|
610
750
|
id: this.id,
|
|
611
|
-
auth,
|
|
751
|
+
auth: auth,
|
|
612
752
|
baseUrl: this.options.baseUrl,
|
|
613
753
|
});
|
|
614
|
-
}
|
|
754
|
+
};
|
|
615
755
|
/**
|
|
616
756
|
* Quick way to change NextGIS Web user.
|
|
617
757
|
* @param credentials - New user credentials
|
|
618
758
|
*/
|
|
619
|
-
login(credentials) {
|
|
759
|
+
NgwConnector.prototype.login = function (credentials) {
|
|
620
760
|
this.logout();
|
|
621
761
|
addConnector(this);
|
|
622
762
|
return this.getUserInfo(credentials);
|
|
623
|
-
}
|
|
763
|
+
};
|
|
624
764
|
/**
|
|
625
765
|
* Disconnecting a user. Aborting all current requests
|
|
626
766
|
*/
|
|
627
|
-
logout() {
|
|
767
|
+
NgwConnector.prototype.logout = function () {
|
|
628
768
|
removeConnector(this);
|
|
629
769
|
this.options.auth = undefined;
|
|
630
770
|
this.user = undefined;
|
|
631
771
|
this.emitter.emit('logout');
|
|
632
772
|
this.resources.cache.clean();
|
|
633
|
-
}
|
|
634
|
-
getUserInfo(credentials) {
|
|
773
|
+
};
|
|
774
|
+
NgwConnector.prototype.getUserInfo = function (credentials) {
|
|
775
|
+
var _this = this;
|
|
635
776
|
if (this.user && this.user.id) {
|
|
636
777
|
return CancelablePromise__default.resolve(this.user);
|
|
637
778
|
}
|
|
638
779
|
if (credentials) {
|
|
639
780
|
this.options.auth = credentials;
|
|
640
781
|
}
|
|
641
|
-
|
|
782
|
+
var options = {
|
|
642
783
|
headers: this.getAuthorizationHeaders(credentials),
|
|
643
784
|
// withCredentials: true
|
|
644
785
|
};
|
|
645
786
|
// Do not use apiRequest('auth.current_user') to avoid circular-references
|
|
646
787
|
return this.makeQuery('/api/component/auth/current_user', {}, options)
|
|
647
|
-
.then((data)
|
|
648
|
-
|
|
649
|
-
|
|
788
|
+
.then(function (data) {
|
|
789
|
+
_this.user = data;
|
|
790
|
+
_this.emitter.emit('login', data);
|
|
650
791
|
return data;
|
|
651
792
|
})
|
|
652
|
-
.catch((er)
|
|
653
|
-
|
|
793
|
+
.catch(function (er) {
|
|
794
|
+
_this.emitter.emit('login:error', er);
|
|
654
795
|
throw er;
|
|
655
796
|
});
|
|
656
|
-
}
|
|
797
|
+
};
|
|
657
798
|
/**
|
|
658
799
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
659
800
|
*/
|
|
660
|
-
getAuthorizationHeaders(credentials) {
|
|
661
|
-
|
|
801
|
+
NgwConnector.prototype.getAuthorizationHeaders = function (credentials) {
|
|
802
|
+
var client = this.makeClientId(credentials);
|
|
662
803
|
if (client) {
|
|
663
804
|
return {
|
|
664
805
|
Authorization: 'Basic ' + client,
|
|
665
806
|
};
|
|
666
807
|
}
|
|
667
|
-
}
|
|
668
|
-
makeClientId(credentials) {
|
|
808
|
+
};
|
|
809
|
+
NgwConnector.prototype.makeClientId = function (credentials) {
|
|
669
810
|
credentials = credentials || this.options.auth;
|
|
670
811
|
if (credentials) {
|
|
671
|
-
|
|
672
|
-
|
|
812
|
+
var login = credentials.login, password = credentials.password;
|
|
813
|
+
var str = unescape(encodeURIComponent("".concat(login, ":").concat(password)));
|
|
673
814
|
// @ts-ignore
|
|
674
815
|
{
|
|
675
816
|
return Buffer.from(str).toString('base64');
|
|
676
817
|
}
|
|
677
818
|
}
|
|
678
|
-
}
|
|
819
|
+
};
|
|
679
820
|
/**
|
|
680
821
|
* Send request to NGW api router.
|
|
681
822
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -705,25 +846,27 @@ class NgwConnector$1 {
|
|
|
705
846
|
*
|
|
706
847
|
* ```
|
|
707
848
|
*/
|
|
708
|
-
apiRequest(name, params_
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
849
|
+
NgwConnector.prototype.apiRequest = function (name, params_, requestOptions) {
|
|
850
|
+
var _this = this;
|
|
851
|
+
if (params_ === void 0) { params_ = {}; }
|
|
852
|
+
if (requestOptions === void 0) { requestOptions = {}; }
|
|
853
|
+
var method = requestOptions.method, headers = requestOptions.headers, withCredentials = requestOptions.withCredentials, responseType = requestOptions.responseType;
|
|
854
|
+
var params = utils.objectRemoveEmpty(params_);
|
|
855
|
+
var makeApiRequest = function () {
|
|
856
|
+
return apiRequest({ name: name, params: params, requestOptions: requestOptions, connector: _this });
|
|
857
|
+
};
|
|
712
858
|
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
|
-
});
|
|
859
|
+
var cache = new Cache__default();
|
|
860
|
+
return cache.add(name, makeApiRequest, __assign({ params: params }, utils.objectRemoveEmpty({
|
|
861
|
+
headers: headers,
|
|
862
|
+
withCredentials: withCredentials,
|
|
863
|
+
responseType: responseType,
|
|
864
|
+
baseUrl: this.options.baseUrl,
|
|
865
|
+
auth: this.options.auth,
|
|
866
|
+
})));
|
|
724
867
|
}
|
|
725
868
|
return makeApiRequest();
|
|
726
|
-
}
|
|
869
|
+
};
|
|
727
870
|
/**
|
|
728
871
|
* Shortcut method for send POST request to NGW.
|
|
729
872
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -737,62 +880,63 @@ class NgwConnector$1 {
|
|
|
737
880
|
* .catch((error) => console.warn(error));
|
|
738
881
|
* ```
|
|
739
882
|
*/
|
|
740
|
-
post(name, options, params) {
|
|
883
|
+
NgwConnector.prototype.post = function (name, options, params) {
|
|
741
884
|
options = options || {};
|
|
742
885
|
options.method = 'POST';
|
|
743
886
|
return this.apiRequest(name, params, options);
|
|
744
|
-
}
|
|
887
|
+
};
|
|
745
888
|
/**
|
|
746
889
|
* Shortcut method for send GET request to NGW.
|
|
747
890
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
748
891
|
* @param options - Request options
|
|
749
892
|
* @param params - Request item params or query params
|
|
750
893
|
*/
|
|
751
|
-
get(name, options, params) {
|
|
894
|
+
NgwConnector.prototype.get = function (name, options, params) {
|
|
752
895
|
options = options || {};
|
|
753
896
|
options.method = 'GET';
|
|
754
897
|
return this.apiRequest(name, params, options);
|
|
755
|
-
}
|
|
898
|
+
};
|
|
756
899
|
/**
|
|
757
900
|
* Shortcut method for send PATCH request to NGW.
|
|
758
901
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
759
902
|
* @param options - Request options
|
|
760
903
|
* @param params - Request item params or query params
|
|
761
904
|
*/
|
|
762
|
-
patch(name, options, params) {
|
|
905
|
+
NgwConnector.prototype.patch = function (name, options, params) {
|
|
763
906
|
options = options || {};
|
|
764
907
|
options.method = 'PATCH';
|
|
765
908
|
return this.apiRequest(name, params, options);
|
|
766
|
-
}
|
|
909
|
+
};
|
|
767
910
|
/**
|
|
768
911
|
* Shortcut method for send PUT request to NGW.
|
|
769
912
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
770
913
|
* @param options - Request options
|
|
771
914
|
* @param params - Request item params or query params
|
|
772
915
|
*/
|
|
773
|
-
put(name, options, params) {
|
|
916
|
+
NgwConnector.prototype.put = function (name, options, params) {
|
|
774
917
|
options = options || {};
|
|
775
918
|
options.method = 'PUT';
|
|
776
919
|
return this.apiRequest(name, params, options);
|
|
777
|
-
}
|
|
920
|
+
};
|
|
778
921
|
/**
|
|
779
922
|
* Shortcut method for send DELETE request to NGW.
|
|
780
923
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
781
924
|
* @param options - Request options
|
|
782
925
|
* @param params - Request item params or query params
|
|
783
926
|
*/
|
|
784
|
-
delete(name, options, params) {
|
|
927
|
+
NgwConnector.prototype.delete = function (name, options, params) {
|
|
785
928
|
options = options || {};
|
|
786
929
|
options.method = 'DELETE';
|
|
787
930
|
return this.apiRequest(name, params, options);
|
|
788
|
-
}
|
|
931
|
+
};
|
|
789
932
|
/**
|
|
790
933
|
* Send request to NGW.
|
|
791
934
|
* @param url - URL address to NGW
|
|
792
935
|
* @param params - Query params
|
|
793
936
|
* @param options - Request options
|
|
794
937
|
*/
|
|
795
|
-
makeQuery(url, params, options
|
|
938
|
+
NgwConnector.prototype.makeQuery = function (url, params, options) {
|
|
939
|
+
if (options === void 0) { options = {}; }
|
|
796
940
|
url = (this.options.baseUrl ? this.options.baseUrl : '') + url;
|
|
797
941
|
if (url) {
|
|
798
942
|
if (params) {
|
|
@@ -805,112 +949,110 @@ class NgwConnector$1 {
|
|
|
805
949
|
else {
|
|
806
950
|
throw new Error('Empty `url` not allowed');
|
|
807
951
|
}
|
|
808
|
-
}
|
|
952
|
+
};
|
|
809
953
|
// -------------------------------------------------------------------------
|
|
810
954
|
// Resource Methods
|
|
811
955
|
// -------------------------------------------------------------------------
|
|
812
956
|
/**
|
|
813
957
|
* {@inheritDoc ResourcesControl.getOne}
|
|
814
958
|
*/
|
|
815
|
-
getResource(resource, requestOptions) {
|
|
959
|
+
NgwConnector.prototype.getResource = function (resource, requestOptions) {
|
|
816
960
|
return this.resources.getOne(resource, requestOptions);
|
|
817
|
-
}
|
|
961
|
+
};
|
|
818
962
|
/**
|
|
819
963
|
* {@inheritDoc ResourcesControl.getOneOrFail}
|
|
820
964
|
*/
|
|
821
|
-
getResourceOrFail(resource, requestOptions) {
|
|
965
|
+
NgwConnector.prototype.getResourceOrFail = function (resource, requestOptions) {
|
|
822
966
|
return this.resources.getOneOrFail(resource, requestOptions);
|
|
823
|
-
}
|
|
967
|
+
};
|
|
824
968
|
/**
|
|
825
969
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
826
970
|
*/
|
|
827
|
-
getResourceBy(resource) {
|
|
971
|
+
NgwConnector.prototype.getResourceBy = function (resource) {
|
|
828
972
|
return this.resources.getOne(resource);
|
|
829
|
-
}
|
|
973
|
+
};
|
|
830
974
|
/**
|
|
831
975
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
832
976
|
*/
|
|
833
|
-
getResourceByKeyname(keyname) {
|
|
977
|
+
NgwConnector.prototype.getResourceByKeyname = function (keyname) {
|
|
834
978
|
return this.resources.getOne(keyname);
|
|
835
|
-
}
|
|
979
|
+
};
|
|
836
980
|
/**
|
|
837
981
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
838
982
|
*/
|
|
839
|
-
getResourceById(id) {
|
|
983
|
+
NgwConnector.prototype.getResourceById = function (id) {
|
|
840
984
|
return this.resources.getOne(id);
|
|
841
|
-
}
|
|
985
|
+
};
|
|
842
986
|
/**
|
|
843
987
|
* {@inheritDoc ResourcesControl.getId}
|
|
844
988
|
*/
|
|
845
|
-
getResourceId(resource, requestOptions) {
|
|
989
|
+
NgwConnector.prototype.getResourceId = function (resource, requestOptions) {
|
|
846
990
|
return this.resources.getId(resource, requestOptions);
|
|
847
|
-
}
|
|
991
|
+
};
|
|
848
992
|
/**
|
|
849
993
|
* {@inheritDoc ResourcesControl.getIdOrFail}
|
|
850
994
|
*/
|
|
851
|
-
getResourceIdOrFail(resource, requestOptions) {
|
|
995
|
+
NgwConnector.prototype.getResourceIdOrFail = function (resource, requestOptions) {
|
|
852
996
|
return this.resources.getIdOrFail(resource, requestOptions);
|
|
853
|
-
}
|
|
997
|
+
};
|
|
854
998
|
/**
|
|
855
999
|
* {@inheritDoc ResourcesControl.getMany}
|
|
856
1000
|
*/
|
|
857
|
-
getResourcesBy(resource, requestOptions) {
|
|
1001
|
+
NgwConnector.prototype.getResourcesBy = function (resource, requestOptions) {
|
|
858
1002
|
return this.resources.getMany(resource, requestOptions);
|
|
859
|
-
}
|
|
1003
|
+
};
|
|
860
1004
|
/**
|
|
861
1005
|
* {@inheritDoc ResourcesControl.getParent}
|
|
862
1006
|
*/
|
|
863
|
-
getResourceParent(resource, requestOptions) {
|
|
1007
|
+
NgwConnector.prototype.getResourceParent = function (resource, requestOptions) {
|
|
864
1008
|
return this.resources.getParent(resource, requestOptions);
|
|
865
|
-
}
|
|
1009
|
+
};
|
|
866
1010
|
/**
|
|
867
1011
|
* {@inheritDoc ResourcesControl.getChildrenOf}
|
|
868
1012
|
*/
|
|
869
|
-
getResourceChildren(resource, requestOptions) {
|
|
1013
|
+
NgwConnector.prototype.getResourceChildren = function (resource, requestOptions) {
|
|
870
1014
|
return this.resources.getChildrenOf(resource, requestOptions);
|
|
871
|
-
}
|
|
1015
|
+
};
|
|
872
1016
|
/**
|
|
873
1017
|
* {@inheritDoc ResourcesControl.update}
|
|
874
1018
|
*/
|
|
875
|
-
updateResource(resource, data) {
|
|
1019
|
+
NgwConnector.prototype.updateResource = function (resource, data) {
|
|
876
1020
|
return this.resources.update(resource, data);
|
|
877
|
-
}
|
|
1021
|
+
};
|
|
878
1022
|
/**
|
|
879
1023
|
* {@inheritDoc ResourcesControl.delete}
|
|
880
1024
|
*/
|
|
881
|
-
deleteResource(resource) {
|
|
1025
|
+
NgwConnector.prototype.deleteResource = function (resource) {
|
|
882
1026
|
return this.resources.delete(resource);
|
|
883
|
-
}
|
|
1027
|
+
};
|
|
884
1028
|
/**
|
|
885
1029
|
* @internal
|
|
886
1030
|
*/
|
|
887
|
-
_loadData(url, options) {
|
|
1031
|
+
NgwConnector.prototype._loadData = function (url, options) {
|
|
1032
|
+
var _this = this;
|
|
888
1033
|
options.responseType = options.responseType || 'json';
|
|
889
|
-
return new CancelablePromise__default((resolve, reject, onCancel)
|
|
890
|
-
if (
|
|
1034
|
+
return new CancelablePromise__default(function (resolve, reject, onCancel) {
|
|
1035
|
+
if (_this.user) {
|
|
891
1036
|
options = options || {};
|
|
892
1037
|
// options.withCredentials = true;
|
|
893
|
-
options.headers = {
|
|
894
|
-
...this.getAuthorizationHeaders(),
|
|
895
|
-
...options.headers,
|
|
896
|
-
};
|
|
1038
|
+
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
897
1039
|
}
|
|
898
1040
|
loadData(url, resolve, options, reject, onCancel);
|
|
899
|
-
}).catch((httpError)
|
|
1041
|
+
}).catch(function (httpError) {
|
|
900
1042
|
if (httpError instanceof CancelablePromise__default.CancelError) ;
|
|
901
1043
|
else {
|
|
902
1044
|
// @ts-ignore
|
|
903
1045
|
{
|
|
904
1046
|
console.warn('DEV WARN', httpError);
|
|
905
1047
|
}
|
|
906
|
-
|
|
1048
|
+
var er = _this._handleHttpError(httpError);
|
|
907
1049
|
if (er) {
|
|
908
1050
|
throw er;
|
|
909
1051
|
}
|
|
910
1052
|
}
|
|
911
1053
|
});
|
|
912
|
-
}
|
|
913
|
-
_handleHttpError(er) {
|
|
1054
|
+
};
|
|
1055
|
+
NgwConnector.prototype._handleHttpError = function (er) {
|
|
914
1056
|
if (er) {
|
|
915
1057
|
if (er instanceof NgwError) {
|
|
916
1058
|
if (er.exception === 'nextgisweb.resource.exception.ResourceNotFound') {
|
|
@@ -922,12 +1064,13 @@ class NgwConnector$1 {
|
|
|
922
1064
|
}
|
|
923
1065
|
}
|
|
924
1066
|
return er;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1067
|
+
};
|
|
1068
|
+
NgwConnector.errors = {
|
|
1069
|
+
NgwError: NgwError,
|
|
1070
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
1071
|
+
};
|
|
1072
|
+
return NgwConnector;
|
|
1073
|
+
}());
|
|
931
1074
|
|
|
932
1075
|
/**
|
|
933
1076
|
* A lightweight HTTP client optimized for use with {@link http://docs.nextgis.ru/docs_ngweb_dev/doc/developer/toc.html | NextGIS Web} API
|