@nextgis/ngw-connector 2.3.0 → 3.0.0-alpha.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 +45 -37
- package/lib/ngw-connector.cjs.js +194 -185
- 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 +321 -548
- package/lib/ngw-connector.esm-browser.js.map +1 -1
- package/lib/ngw-connector.esm-browser.prod.js +1 -1
- package/lib/ngw-connector.esm-browser.prod.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.js +304 -217
- package/lib/ngw-connector.esm-bundler.js.map +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js +1 -1
- package/lib/ngw-connector.esm-bundler.prod.js.map +1 -1
- package/lib/ngw-connector.global.js +321 -548
- package/lib/ngw-connector.global.js.map +1 -1
- package/lib/ngw-connector.global.prod.js +1 -1
- package/lib/ngw-connector.global.prod.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version:
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.0; author: NextGIS */
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import Cache from '@nextgis/cache';
|
|
4
|
-
import CancelablePromise from '@nextgis/cancelable-promise';
|
|
5
4
|
import { objectDeepEqual, defined, objectRemoveEmpty, fixUrlStr } from '@nextgis/utils';
|
|
6
5
|
|
|
7
|
-
var __defProp$
|
|
8
|
-
var __defNormalProp$
|
|
9
|
-
var __publicField$5 = (obj, key, value) => __defNormalProp$
|
|
6
|
+
var __defProp$6 = Object.defineProperty;
|
|
7
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
9
|
class NgwError extends Error {
|
|
11
10
|
constructor(er) {
|
|
12
11
|
super();
|
|
@@ -23,9 +22,9 @@ class NgwError extends Error {
|
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
var __defProp$
|
|
27
|
-
var __defNormalProp$
|
|
28
|
-
var __publicField$4 = (obj, key, value) => __defNormalProp$
|
|
25
|
+
var __defProp$5 = Object.defineProperty;
|
|
26
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
27
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
28
|
class ResourceNotFoundError extends NgwError {
|
|
30
29
|
constructor(obj) {
|
|
31
30
|
super(obj);
|
|
@@ -64,27 +63,24 @@ function resourceToQuery(resource, prefix = "") {
|
|
|
64
63
|
return query;
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
var __defProp$
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
74
|
-
var __spreadValues$1 = (a, b) => {
|
|
66
|
+
var __defProp$4 = Object.defineProperty;
|
|
67
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
68
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
69
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
70
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
71
|
+
var __spreadValues$2 = (a, b) => {
|
|
75
72
|
for (var prop in b || (b = {}))
|
|
76
|
-
if (__hasOwnProp$
|
|
77
|
-
__defNormalProp$
|
|
78
|
-
if (__getOwnPropSymbols$
|
|
79
|
-
for (var prop of __getOwnPropSymbols$
|
|
80
|
-
if (__propIsEnum$
|
|
81
|
-
__defNormalProp$
|
|
73
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
74
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
75
|
+
if (__getOwnPropSymbols$2)
|
|
76
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
77
|
+
if (__propIsEnum$2.call(b, prop))
|
|
78
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
82
79
|
}
|
|
83
80
|
return a;
|
|
84
81
|
};
|
|
85
|
-
var
|
|
86
|
-
var
|
|
87
|
-
var __async = (__this, __arguments, generator) => {
|
|
82
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
83
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
88
84
|
return new Promise((resolve, reject) => {
|
|
89
85
|
var fulfilled = (value) => {
|
|
90
86
|
try {
|
|
@@ -125,36 +121,27 @@ class ResourcesControl {
|
|
|
125
121
|
* Fetching resource would be cached to speed up next call
|
|
126
122
|
*/
|
|
127
123
|
getOne(resource, requestOptions) {
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const opt = __spreadProps(__spreadValues$1({}, requestOptions), { cache: false });
|
|
131
|
-
if (typeof resource === "string") {
|
|
132
|
-
forCache.keyname = resource;
|
|
133
|
-
} else if (typeof resource === "number") {
|
|
134
|
-
forCache.id = resource;
|
|
135
|
-
} else if (isObject(resource)) {
|
|
124
|
+
const opt = __spreadValues$2({}, requestOptions);
|
|
125
|
+
if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
|
|
136
126
|
if (resource.id !== void 0) {
|
|
137
|
-
|
|
127
|
+
resource.id;
|
|
138
128
|
} else {
|
|
139
129
|
if (resource.keyname) {
|
|
140
|
-
|
|
130
|
+
resource.keyname;
|
|
141
131
|
}
|
|
142
132
|
if (resource.display_name) {
|
|
143
|
-
|
|
133
|
+
resource.display_name;
|
|
144
134
|
}
|
|
145
135
|
}
|
|
146
136
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return CancelablePromise.resolve(void 0);
|
|
156
|
-
};
|
|
157
|
-
return cache.addFull("resource", makeRequest, forCache);
|
|
137
|
+
if (typeof resource === "string") {
|
|
138
|
+
return this._fetchResourceBy({ keyname: resource }, opt);
|
|
139
|
+
} else if (typeof resource === "number") {
|
|
140
|
+
return this._fetchResourceById(resource, opt);
|
|
141
|
+
} else if (isObject(resource)) {
|
|
142
|
+
return this._fetchResourceBy(resource, opt);
|
|
143
|
+
}
|
|
144
|
+
return Promise.resolve(void 0);
|
|
158
145
|
}
|
|
159
146
|
getOneOrFail(resource, requestOptions) {
|
|
160
147
|
return this.getOne(resource, requestOptions).then((res) => {
|
|
@@ -176,7 +163,7 @@ class ResourcesControl {
|
|
|
176
163
|
*/
|
|
177
164
|
getId(resource, requestOptions) {
|
|
178
165
|
if (typeof resource === "number") {
|
|
179
|
-
return
|
|
166
|
+
return Promise.resolve(resource);
|
|
180
167
|
} else if (typeof resource === "string" || isObject(resource)) {
|
|
181
168
|
return this.getOne(resource, requestOptions).then((res) => {
|
|
182
169
|
if (res) {
|
|
@@ -184,7 +171,7 @@ class ResourcesControl {
|
|
|
184
171
|
}
|
|
185
172
|
});
|
|
186
173
|
}
|
|
187
|
-
return
|
|
174
|
+
return Promise.resolve(void 0);
|
|
188
175
|
}
|
|
189
176
|
/**
|
|
190
177
|
* A fast way to retrieve resource ID for any resource definition.
|
|
@@ -211,12 +198,12 @@ class ResourcesControl {
|
|
|
211
198
|
} else {
|
|
212
199
|
Object.assign(query, resourceToQuery(resource));
|
|
213
200
|
}
|
|
214
|
-
return this.connector.get("resource.search", requestOptions, __spreadValues$
|
|
201
|
+
return this.connector.get("resource.search", requestOptions, __spreadValues$2({
|
|
215
202
|
serialization: "full"
|
|
216
203
|
}, query)).then((resources) => {
|
|
217
|
-
if (resources) {
|
|
204
|
+
if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
|
|
218
205
|
for (const x of resources) {
|
|
219
|
-
this.cache.add("resource.item",
|
|
206
|
+
this.cache.add("resource.item", Promise.resolve(x), {
|
|
220
207
|
id: x.resource.id
|
|
221
208
|
});
|
|
222
209
|
}
|
|
@@ -232,7 +219,7 @@ class ResourcesControl {
|
|
|
232
219
|
if (child) {
|
|
233
220
|
return this.getOne(child.resource.parent.id, requestOptions);
|
|
234
221
|
}
|
|
235
|
-
return
|
|
222
|
+
return Promise.resolve(void 0);
|
|
236
223
|
});
|
|
237
224
|
}
|
|
238
225
|
getChildrenOf(resource, requestOptions) {
|
|
@@ -262,18 +249,16 @@ class ResourcesControl {
|
|
|
262
249
|
});
|
|
263
250
|
}
|
|
264
251
|
_getChildrenOf(parent, requestOptions, _items = []) {
|
|
265
|
-
return this.connector.get(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
{
|
|
269
|
-
parent
|
|
270
|
-
}
|
|
271
|
-
).then((items) => {
|
|
252
|
+
return this.connector.get("resource.collection", requestOptions, {
|
|
253
|
+
parent
|
|
254
|
+
}).then((items) => {
|
|
272
255
|
const recursivePromises = [];
|
|
273
256
|
for (const item of items) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
257
|
+
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
258
|
+
this.cache.add("resource.item", Promise.resolve(item), {
|
|
259
|
+
id: item.resource.id
|
|
260
|
+
});
|
|
261
|
+
}
|
|
277
262
|
_items.push(item);
|
|
278
263
|
if ((requestOptions == null ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
279
264
|
recursivePromises.push(
|
|
@@ -282,7 +267,7 @@ class ResourcesControl {
|
|
|
282
267
|
}
|
|
283
268
|
}
|
|
284
269
|
if (recursivePromises.length) {
|
|
285
|
-
return
|
|
270
|
+
return Promise.all(recursivePromises).then(() => {
|
|
286
271
|
return _items;
|
|
287
272
|
});
|
|
288
273
|
}
|
|
@@ -290,11 +275,12 @@ class ResourcesControl {
|
|
|
290
275
|
});
|
|
291
276
|
}
|
|
292
277
|
_cleanResourceItemCache(id) {
|
|
293
|
-
return __async(this, null, function* () {
|
|
278
|
+
return __async$2(this, null, function* () {
|
|
279
|
+
var _a;
|
|
294
280
|
const all = this.cache.all();
|
|
295
281
|
const toDelete = [];
|
|
296
282
|
for (const c of all) {
|
|
297
|
-
const cid = c.
|
|
283
|
+
const cid = (_a = c.props) == null ? void 0 : _a.id;
|
|
298
284
|
if (["resource.item", "resource"].includes(c.key) && cid !== void 0) {
|
|
299
285
|
if (typeof cid === "number") {
|
|
300
286
|
if (cid === id) {
|
|
@@ -314,15 +300,7 @@ class ResourcesControl {
|
|
|
314
300
|
});
|
|
315
301
|
}
|
|
316
302
|
_fetchResourceById(id, requestOptions) {
|
|
317
|
-
|
|
318
|
-
return this.cache.add("resource.item", promise, {
|
|
319
|
-
id
|
|
320
|
-
}).catch((er) => {
|
|
321
|
-
if (!(er instanceof ResourceNotFoundError)) {
|
|
322
|
-
throw er;
|
|
323
|
-
}
|
|
324
|
-
return void 0;
|
|
325
|
-
});
|
|
303
|
+
return this.connector.get("resource.item", requestOptions, { id });
|
|
326
304
|
}
|
|
327
305
|
_fetchResourceBy(resource, requestOptions) {
|
|
328
306
|
return this.getMany(resource, requestOptions).then((resources) => {
|
|
@@ -330,7 +308,7 @@ class ResourcesControl {
|
|
|
330
308
|
});
|
|
331
309
|
}
|
|
332
310
|
_resourceCacheFilter(resource) {
|
|
333
|
-
return
|
|
311
|
+
return Promise.all(this.cache.matchAll("resource.item")).then(
|
|
334
312
|
(resources) => {
|
|
335
313
|
const items = [];
|
|
336
314
|
resources.filter((x) => {
|
|
@@ -374,9 +352,16 @@ function removeConnector(connector) {
|
|
|
374
352
|
}
|
|
375
353
|
}
|
|
376
354
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
355
|
+
class AbortError extends Error {
|
|
356
|
+
constructor(message = "AbortError") {
|
|
357
|
+
super(message);
|
|
358
|
+
this.name = "AbortError";
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
var __defProp$3 = Object.defineProperty;
|
|
363
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
364
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
380
365
|
class InsufficientPermissionsError extends NgwError {
|
|
381
366
|
constructor(obj) {
|
|
382
367
|
super(obj);
|
|
@@ -399,64 +384,96 @@ function template(str, data) {
|
|
|
399
384
|
});
|
|
400
385
|
}
|
|
401
386
|
|
|
387
|
+
var __defProp$2 = Object.defineProperty;
|
|
388
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
389
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
390
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
391
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
392
|
+
var __spreadValues$1 = (a, b) => {
|
|
393
|
+
for (var prop in b || (b = {}))
|
|
394
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
395
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
396
|
+
if (__getOwnPropSymbols$1)
|
|
397
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
398
|
+
if (__propIsEnum$1.call(b, prop))
|
|
399
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
400
|
+
}
|
|
401
|
+
return a;
|
|
402
|
+
};
|
|
403
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
404
|
+
return new Promise((resolve, reject) => {
|
|
405
|
+
var fulfilled = (value) => {
|
|
406
|
+
try {
|
|
407
|
+
step(generator.next(value));
|
|
408
|
+
} catch (e) {
|
|
409
|
+
reject(e);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var rejected = (value) => {
|
|
413
|
+
try {
|
|
414
|
+
step(generator.throw(value));
|
|
415
|
+
} catch (e) {
|
|
416
|
+
reject(e);
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
420
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
421
|
+
});
|
|
422
|
+
};
|
|
402
423
|
function apiRequest(opt) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
"`" + arg + "` url api argument is not specified"
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
if (url) {
|
|
422
|
-
url = template(url, replaceParams);
|
|
424
|
+
return __async$1(this, null, function* () {
|
|
425
|
+
const { params, name, connector, requestOptions } = opt;
|
|
426
|
+
const apiItems = yield connector.connect();
|
|
427
|
+
let apiItem = apiItems && apiItems[name];
|
|
428
|
+
if (apiItem) {
|
|
429
|
+
apiItem = [...apiItem];
|
|
430
|
+
let url = apiItem.shift();
|
|
431
|
+
if (apiItem.length) {
|
|
432
|
+
const replaceParams = {};
|
|
433
|
+
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
434
|
+
const arg = apiItem[fry];
|
|
435
|
+
replaceParams[fry] = `{${arg}}`;
|
|
436
|
+
if (params[arg] === void 0) {
|
|
437
|
+
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
423
438
|
}
|
|
424
439
|
}
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
url = url + "?" + paramArray.join("&");
|
|
440
|
+
if (url) {
|
|
441
|
+
url = template(url, replaceParams);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (params) {
|
|
445
|
+
const paramArray = [];
|
|
446
|
+
const paramList = params.paramList;
|
|
447
|
+
if (Array.isArray(paramList)) {
|
|
448
|
+
paramList.forEach(([key, value]) => {
|
|
449
|
+
paramArray.push(`${key}=${value}`);
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
for (const p in params) {
|
|
453
|
+
if (apiItem.indexOf(p) === -1) {
|
|
454
|
+
paramArray.push(`${p}=${params[p]}`);
|
|
441
455
|
}
|
|
442
456
|
}
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
} else {
|
|
446
|
-
reject(new Error("request url is not set"));
|
|
457
|
+
if (paramArray.length) {
|
|
458
|
+
url = `${url}?${paramArray.join("&")}`;
|
|
447
459
|
}
|
|
460
|
+
}
|
|
461
|
+
if (url) {
|
|
462
|
+
return connector.makeQuery(url, params, __spreadValues$1({
|
|
463
|
+
cacheName: name
|
|
464
|
+
}, requestOptions));
|
|
448
465
|
} else {
|
|
449
|
-
|
|
466
|
+
throw new Error("Request URL is not set");
|
|
450
467
|
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
}
|
|
468
|
+
} else {
|
|
469
|
+
return void 0;
|
|
470
|
+
}
|
|
454
471
|
});
|
|
455
472
|
}
|
|
456
473
|
|
|
457
474
|
var __defProp$1 = Object.defineProperty;
|
|
458
475
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
459
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj,
|
|
476
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
|
|
460
477
|
class NetworkError extends Error {
|
|
461
478
|
constructor(url) {
|
|
462
479
|
super();
|
|
@@ -550,6 +567,8 @@ let loadData;
|
|
|
550
567
|
}
|
|
551
568
|
|
|
552
569
|
var __defProp = Object.defineProperty;
|
|
570
|
+
var __defProps = Object.defineProperties;
|
|
571
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
553
572
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
554
573
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
555
574
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -565,8 +584,42 @@ var __spreadValues = (a, b) => {
|
|
|
565
584
|
}
|
|
566
585
|
return a;
|
|
567
586
|
};
|
|
587
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
588
|
+
var __objRest = (source, exclude) => {
|
|
589
|
+
var target = {};
|
|
590
|
+
for (var prop in source)
|
|
591
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
592
|
+
target[prop] = source[prop];
|
|
593
|
+
if (source != null && __getOwnPropSymbols)
|
|
594
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
595
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
596
|
+
target[prop] = source[prop];
|
|
597
|
+
}
|
|
598
|
+
return target;
|
|
599
|
+
};
|
|
568
600
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
601
|
+
var __async = (__this, __arguments, generator) => {
|
|
602
|
+
return new Promise((resolve, reject) => {
|
|
603
|
+
var fulfilled = (value) => {
|
|
604
|
+
try {
|
|
605
|
+
step(generator.next(value));
|
|
606
|
+
} catch (e) {
|
|
607
|
+
reject(e);
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
var rejected = (value) => {
|
|
611
|
+
try {
|
|
612
|
+
step(generator.throw(value));
|
|
613
|
+
} catch (e) {
|
|
614
|
+
reject(e);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
618
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
619
|
+
});
|
|
620
|
+
};
|
|
569
621
|
let ID = 0;
|
|
622
|
+
let REQUEST_ID = 0;
|
|
570
623
|
class NgwConnector {
|
|
571
624
|
constructor(options) {
|
|
572
625
|
this.options = options;
|
|
@@ -576,7 +629,7 @@ class NgwConnector {
|
|
|
576
629
|
__publicField(this, "resources");
|
|
577
630
|
__publicField(this, "cache");
|
|
578
631
|
__publicField(this, "routeStr", "/api/component/pyramid/route");
|
|
579
|
-
__publicField(this, "activeRequests",
|
|
632
|
+
__publicField(this, "activeRequests", {});
|
|
580
633
|
__publicField(this, "requestTransform");
|
|
581
634
|
const exist = findConnector(options);
|
|
582
635
|
this.cache = new Cache({ namespace: options.cacheId });
|
|
@@ -633,29 +686,27 @@ class NgwConnector {
|
|
|
633
686
|
* ```
|
|
634
687
|
*/
|
|
635
688
|
connect() {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const makeQuery = () => {
|
|
639
|
-
return this.makeQuery(this.routeStr, {}, {}).then((route) => {
|
|
640
|
-
resolve(route);
|
|
641
|
-
}).catch((er) => {
|
|
642
|
-
reject(er);
|
|
643
|
-
});
|
|
644
|
-
};
|
|
689
|
+
return __async(this, null, function* () {
|
|
690
|
+
const auth = this.options.auth;
|
|
645
691
|
if (auth) {
|
|
646
692
|
const { login, password } = auth;
|
|
647
693
|
if (login && password) {
|
|
648
|
-
|
|
649
|
-
return makeQuery();
|
|
650
|
-
}).catch((er) => reject(er));
|
|
694
|
+
yield this._login({ login, password });
|
|
651
695
|
}
|
|
652
696
|
}
|
|
653
|
-
return makeQuery(
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
697
|
+
return yield this.makeQuery(
|
|
698
|
+
this.routeStr,
|
|
699
|
+
{},
|
|
700
|
+
{
|
|
701
|
+
cacheName: "route",
|
|
702
|
+
cache: true,
|
|
703
|
+
cacheProps: {
|
|
704
|
+
id: this.id,
|
|
705
|
+
auth,
|
|
706
|
+
baseUrl: this.options.baseUrl
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
);
|
|
659
710
|
});
|
|
660
711
|
}
|
|
661
712
|
/**
|
|
@@ -679,20 +730,22 @@ class NgwConnector {
|
|
|
679
730
|
this.emitter.emit("logout");
|
|
680
731
|
}
|
|
681
732
|
getUserInfo(credentials, options) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
733
|
+
return __async(this, null, function* () {
|
|
734
|
+
if (this.user && this.user.id) {
|
|
735
|
+
return this.user;
|
|
736
|
+
}
|
|
737
|
+
if (credentials) {
|
|
738
|
+
this.options.auth = credentials;
|
|
739
|
+
}
|
|
740
|
+
const options_ = __spreadValues({
|
|
741
|
+
headers: this.getAuthorizationHeaders(credentials)
|
|
742
|
+
}, options);
|
|
743
|
+
return this.makeQuery(
|
|
744
|
+
"/api/component/auth/current_user",
|
|
745
|
+
{},
|
|
746
|
+
options_
|
|
747
|
+
);
|
|
748
|
+
});
|
|
696
749
|
}
|
|
697
750
|
/**
|
|
698
751
|
* Obtaining the required Headers for authentication of requests in the NGW.
|
|
@@ -701,7 +754,7 @@ class NgwConnector {
|
|
|
701
754
|
const client = this.makeClientId(credentials);
|
|
702
755
|
if (client) {
|
|
703
756
|
return {
|
|
704
|
-
Authorization:
|
|
757
|
+
Authorization: `Basic ${client}`
|
|
705
758
|
};
|
|
706
759
|
}
|
|
707
760
|
}
|
|
@@ -709,21 +762,22 @@ class NgwConnector {
|
|
|
709
762
|
credentials = credentials || this.options.auth;
|
|
710
763
|
if (credentials) {
|
|
711
764
|
const { login, password } = credentials;
|
|
712
|
-
const str =
|
|
765
|
+
const str = `${login}:${password}`;
|
|
766
|
+
const encodedStr = encodeURIComponent(str);
|
|
713
767
|
{
|
|
714
|
-
return window.btoa(
|
|
768
|
+
return window.btoa(encodedStr);
|
|
715
769
|
}
|
|
716
770
|
}
|
|
717
771
|
}
|
|
718
772
|
/** Stop all api requests */
|
|
719
773
|
abort() {
|
|
720
|
-
for (const
|
|
721
|
-
|
|
774
|
+
for (const abortController of Object.values(this.activeRequests)) {
|
|
775
|
+
abortController.abort();
|
|
722
776
|
}
|
|
723
|
-
this.activeRequests =
|
|
777
|
+
this.activeRequests = {};
|
|
724
778
|
}
|
|
725
779
|
getActiveApiRequests() {
|
|
726
|
-
return
|
|
780
|
+
return __spreadValues({}, this.activeRequests);
|
|
727
781
|
}
|
|
728
782
|
/**
|
|
729
783
|
* Send request to NGW api router.
|
|
@@ -755,23 +809,10 @@ class NgwConnector {
|
|
|
755
809
|
* ```
|
|
756
810
|
*/
|
|
757
811
|
apiRequest(name, params_ = {}, requestOptions = {}) {
|
|
758
|
-
var _a
|
|
759
|
-
const { method, headers, withCredentials, responseType } = requestOptions;
|
|
812
|
+
var _a;
|
|
760
813
|
params_ = (_a = requestOptions.params) != null ? _a : params_;
|
|
761
814
|
const params = objectRemoveEmpty(params_);
|
|
762
|
-
|
|
763
|
-
if (requestOptions.cache && method === "GET") {
|
|
764
|
-
return this.cache.add(name, makeApiRequest, __spreadValues({
|
|
765
|
-
params
|
|
766
|
-
}, objectRemoveEmpty({
|
|
767
|
-
headers,
|
|
768
|
-
withCredentials,
|
|
769
|
-
responseType,
|
|
770
|
-
baseUrl: this.options.baseUrl,
|
|
771
|
-
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
772
|
-
})));
|
|
773
|
-
}
|
|
774
|
-
return makeApiRequest();
|
|
815
|
+
return apiRequest({ name, params, requestOptions, connector: this });
|
|
775
816
|
}
|
|
776
817
|
/**
|
|
777
818
|
* Shortcut method for send POST request to NGW.
|
|
@@ -861,17 +902,67 @@ class NgwConnector {
|
|
|
861
902
|
* @param params - Query params
|
|
862
903
|
* @param options - Request options
|
|
863
904
|
*/
|
|
864
|
-
makeQuery(
|
|
865
|
-
|
|
866
|
-
|
|
905
|
+
makeQuery(_0, _1) {
|
|
906
|
+
return __async(this, arguments, function* (url, params, options = {}) {
|
|
907
|
+
var _b;
|
|
908
|
+
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
909
|
+
if (!url) {
|
|
910
|
+
throw new Error("Empty `url` not allowed");
|
|
911
|
+
}
|
|
867
912
|
if (params) {
|
|
868
|
-
|
|
913
|
+
const _a = params, restParams = __objRest(_a, ["paramList"]);
|
|
914
|
+
url = template(url, restParams);
|
|
869
915
|
}
|
|
870
916
|
url = encodeURI(fixUrlStr(url));
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
917
|
+
const {
|
|
918
|
+
cache,
|
|
919
|
+
signal: externalSignal,
|
|
920
|
+
method = "GET",
|
|
921
|
+
headers,
|
|
922
|
+
cacheName,
|
|
923
|
+
cacheProps,
|
|
924
|
+
responseType,
|
|
925
|
+
withCredentials
|
|
926
|
+
} = options;
|
|
927
|
+
const internalAbortController = new AbortController();
|
|
928
|
+
const internalSignal = internalAbortController.signal;
|
|
929
|
+
if (externalSignal) {
|
|
930
|
+
if (externalSignal.aborted) {
|
|
931
|
+
throw new AbortError();
|
|
932
|
+
}
|
|
933
|
+
externalSignal.addEventListener("abort", () => {
|
|
934
|
+
internalAbortController.abort();
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
options.signal = internalSignal;
|
|
938
|
+
const createPromise = () => __async(this, null, function* () {
|
|
939
|
+
const id = REQUEST_ID++;
|
|
940
|
+
this.activeRequests[id] = internalAbortController;
|
|
941
|
+
try {
|
|
942
|
+
return this._loadData(url, options);
|
|
943
|
+
} finally {
|
|
944
|
+
this._cleanActiveRequest(id);
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
if (cache && method === "GET") {
|
|
948
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues({}, objectRemoveEmpty({
|
|
949
|
+
headers,
|
|
950
|
+
withCredentials,
|
|
951
|
+
responseType,
|
|
952
|
+
baseUrl: this.options.baseUrl,
|
|
953
|
+
userId: (_b = this.user) == null ? void 0 : _b.id
|
|
954
|
+
})), {
|
|
955
|
+
params
|
|
956
|
+
});
|
|
957
|
+
return this.cache.add(
|
|
958
|
+
cacheName || url,
|
|
959
|
+
createPromise,
|
|
960
|
+
cacheOptions,
|
|
961
|
+
false
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
return createPromise();
|
|
965
|
+
});
|
|
875
966
|
}
|
|
876
967
|
// -------------------------------------------------------------------------
|
|
877
968
|
// Resource Methods
|
|
@@ -953,10 +1044,8 @@ class NgwConnector {
|
|
|
953
1044
|
*/
|
|
954
1045
|
_loadData(url, options) {
|
|
955
1046
|
options.responseType = options.responseType || "json";
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
}
|
|
959
|
-
const request = new CancelablePromise((resolve, reject, onCancel) => {
|
|
1047
|
+
return new Promise((resolve, reject) => {
|
|
1048
|
+
var _a;
|
|
960
1049
|
if (this.user) {
|
|
961
1050
|
options = options || {};
|
|
962
1051
|
options.headers = __spreadValues(__spreadValues({}, this.getAuthorizationHeaders()), options.headers);
|
|
@@ -966,13 +1055,18 @@ class NgwConnector {
|
|
|
966
1055
|
url = transUrl;
|
|
967
1056
|
options = transOptions;
|
|
968
1057
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1058
|
+
let runOnAbort = void 0;
|
|
1059
|
+
loadData(url, resolve, options, reject, (handler) => {
|
|
1060
|
+
runOnAbort = handler;
|
|
1061
|
+
});
|
|
1062
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1063
|
+
if (runOnAbort !== void 0) {
|
|
1064
|
+
runOnAbort();
|
|
1065
|
+
}
|
|
1066
|
+
reject(new AbortError());
|
|
1067
|
+
});
|
|
973
1068
|
}).catch((httpError) => {
|
|
974
|
-
|
|
975
|
-
if (httpError instanceof CancelablePromise.CancelError) ; else {
|
|
1069
|
+
if (httpError.name !== "AbortError") {
|
|
976
1070
|
if (!!(process.env.NODE_ENV !== "production")) {
|
|
977
1071
|
console.warn("DEV WARN", httpError);
|
|
978
1072
|
}
|
|
@@ -981,31 +1075,24 @@ class NgwConnector {
|
|
|
981
1075
|
throw er;
|
|
982
1076
|
}
|
|
983
1077
|
}
|
|
1078
|
+
throw httpError;
|
|
984
1079
|
});
|
|
985
|
-
if (options.signal && typeof options.signal.addEventListener === "function") {
|
|
986
|
-
options.signal.addEventListener("abort", () => {
|
|
987
|
-
request.cancel();
|
|
988
|
-
this._cleanActiveRequests(request);
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
this.activeRequests.push(request);
|
|
992
|
-
return request;
|
|
993
1080
|
}
|
|
994
1081
|
_login(credentials, options) {
|
|
995
|
-
return this
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1082
|
+
return __async(this, null, function* () {
|
|
1083
|
+
try {
|
|
1084
|
+
const data = yield this.getUserInfo(credentials, options);
|
|
1085
|
+
this.user = data;
|
|
1086
|
+
this.emitter.emit("login", data);
|
|
1087
|
+
return data;
|
|
1088
|
+
} catch (er) {
|
|
1089
|
+
this.emitter.emit("login:error", er);
|
|
1090
|
+
throw er;
|
|
1091
|
+
}
|
|
1002
1092
|
});
|
|
1003
1093
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
if (activeRequestIndex !== -1) {
|
|
1007
|
-
this.activeRequests.splice(activeRequestIndex, 1);
|
|
1008
|
-
}
|
|
1094
|
+
_cleanActiveRequest(requestId) {
|
|
1095
|
+
delete this.activeRequests[requestId];
|
|
1009
1096
|
}
|
|
1010
1097
|
_handleHttpError(er) {
|
|
1011
1098
|
if (er) {
|