@nextgis/ngw-connector 3.0.0-alpha.12 → 3.0.0-alpha.13
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/README.md +48 -13
- package/lib/index.d.ts +51 -31
- package/lib/ngw-connector.cjs.js +160 -152
- 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 +430 -422
- 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 +293 -285
- 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 +430 -422
- 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,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.13; author: NextGIS */
|
|
2
2
|
var NgwConnector = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -63,6 +63,245 @@ var NgwConnector = (function () {
|
|
|
63
63
|
return url.replace(/([^:]\/)\/+/g, "$1");
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
67
|
+
function template(str, data) {
|
|
68
|
+
return str.replace(templateRe, (s, key) => {
|
|
69
|
+
let value = data[key];
|
|
70
|
+
if (value === void 0) {
|
|
71
|
+
throw new Error("No value provided for letiable " + s);
|
|
72
|
+
} else if (typeof value === "function") {
|
|
73
|
+
value = value(data);
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var __defProp$c = Object.defineProperty;
|
|
80
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
81
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
82
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
83
|
+
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
84
|
+
var __spreadValues$4 = (a, b) => {
|
|
85
|
+
for (var prop in b || (b = {}))
|
|
86
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
87
|
+
__defNormalProp$c(a, prop, b[prop]);
|
|
88
|
+
if (__getOwnPropSymbols$4)
|
|
89
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
90
|
+
if (__propIsEnum$4.call(b, prop))
|
|
91
|
+
__defNormalProp$c(a, prop, b[prop]);
|
|
92
|
+
}
|
|
93
|
+
return a;
|
|
94
|
+
};
|
|
95
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
var fulfilled = (value) => {
|
|
98
|
+
try {
|
|
99
|
+
step(generator.next(value));
|
|
100
|
+
} catch (e) {
|
|
101
|
+
reject(e);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var rejected = (value) => {
|
|
105
|
+
try {
|
|
106
|
+
step(generator.throw(value));
|
|
107
|
+
} catch (e) {
|
|
108
|
+
reject(e);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
112
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
function apiRequest(opt) {
|
|
116
|
+
return __async$4(this, null, function* () {
|
|
117
|
+
const { params, name, connector, requestOptions } = opt;
|
|
118
|
+
const apiItems = yield connector.connect();
|
|
119
|
+
let apiItem = apiItems && apiItems[name];
|
|
120
|
+
if (apiItem) {
|
|
121
|
+
apiItem = [...apiItem];
|
|
122
|
+
let url = apiItem.shift();
|
|
123
|
+
if (apiItem.length) {
|
|
124
|
+
const replaceParams = {};
|
|
125
|
+
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
126
|
+
const arg = apiItem[fry];
|
|
127
|
+
replaceParams[fry] = `{${arg}}`;
|
|
128
|
+
if (params[arg] === void 0) {
|
|
129
|
+
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (url) {
|
|
133
|
+
url = template(url, replaceParams);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (params) {
|
|
137
|
+
const paramArray = [];
|
|
138
|
+
const paramList = params.paramList;
|
|
139
|
+
if (Array.isArray(paramList)) {
|
|
140
|
+
paramList.forEach(([key, value]) => {
|
|
141
|
+
paramArray.push(`${key}=${value}`);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
for (const p in params) {
|
|
145
|
+
if (apiItem.indexOf(p) === -1) {
|
|
146
|
+
paramArray.push(`${p}=${params[p]}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (paramArray.length) {
|
|
150
|
+
url = `${url}?${paramArray.join("&")}`;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (url) {
|
|
154
|
+
return connector.makeQuery(url, params, __spreadValues$4({
|
|
155
|
+
cacheName: name
|
|
156
|
+
}, requestOptions));
|
|
157
|
+
} else {
|
|
158
|
+
throw new Error("Request URL is not set");
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
return void 0;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
var __defProp$b = Object.defineProperty;
|
|
167
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
168
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
169
|
+
const _Cache = class _Cache {
|
|
170
|
+
constructor(options = {}) {
|
|
171
|
+
__publicField$9(this, "cache", []);
|
|
172
|
+
var _a;
|
|
173
|
+
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
174
|
+
if (_Cache.instance[namespace]) {
|
|
175
|
+
return _Cache.instance[namespace];
|
|
176
|
+
}
|
|
177
|
+
_Cache.instance[namespace] = this;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
clean() {
|
|
181
|
+
this.cache.length = 0;
|
|
182
|
+
}
|
|
183
|
+
all() {
|
|
184
|
+
return this.cache;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Caching only a non-empty value.
|
|
188
|
+
*
|
|
189
|
+
* Useful for get or create strategy
|
|
190
|
+
* @example
|
|
191
|
+
* ```javascript
|
|
192
|
+
* const cache = new Cache();
|
|
193
|
+
* const getItemFunc = () => fetch(url).then((data) => {
|
|
194
|
+
* return data.json(); // undefined
|
|
195
|
+
* });
|
|
196
|
+
* const item = await cache.addFull('foo', getItemFunc);
|
|
197
|
+
* if (!item) {
|
|
198
|
+
* await createItem(); // 'New item'
|
|
199
|
+
* }
|
|
200
|
+
*
|
|
201
|
+
* // somewhere else in the code
|
|
202
|
+
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
203
|
+
* console.log(resp); // 'New item'
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
addFull(key, valueToSet, propsOrOptions, expirationTime) {
|
|
208
|
+
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
209
|
+
propsOrOptions.onlyFull = true;
|
|
210
|
+
}
|
|
211
|
+
return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
|
|
212
|
+
}
|
|
213
|
+
add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
|
|
214
|
+
let opt;
|
|
215
|
+
let props;
|
|
216
|
+
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
217
|
+
opt = propsOrOptions;
|
|
218
|
+
onlyFull = opt.onlyFull;
|
|
219
|
+
expirationTime = opt.expirationTime;
|
|
220
|
+
props = opt.props;
|
|
221
|
+
} else {
|
|
222
|
+
props = propsOrOptions;
|
|
223
|
+
}
|
|
224
|
+
const exist = this._find(key, props);
|
|
225
|
+
if (!exist) {
|
|
226
|
+
let value;
|
|
227
|
+
if (valueToSet instanceof Function) {
|
|
228
|
+
value = valueToSet();
|
|
229
|
+
} else {
|
|
230
|
+
value = valueToSet;
|
|
231
|
+
}
|
|
232
|
+
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
233
|
+
expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
|
|
234
|
+
const cacheItem = {
|
|
235
|
+
key,
|
|
236
|
+
value,
|
|
237
|
+
props: nonEmptyProps,
|
|
238
|
+
expirationTime
|
|
239
|
+
};
|
|
240
|
+
if (onlyFull && !full(value)) {
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
243
|
+
this.cache.push(cacheItem);
|
|
244
|
+
if (value instanceof Promise) {
|
|
245
|
+
value.catch(() => {
|
|
246
|
+
this.delete(key, props);
|
|
247
|
+
});
|
|
248
|
+
if (onlyFull) {
|
|
249
|
+
value.then((x) => {
|
|
250
|
+
if (!full(x)) {
|
|
251
|
+
this.delete(key, props);
|
|
252
|
+
}
|
|
253
|
+
return x;
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return value;
|
|
257
|
+
}
|
|
258
|
+
return value;
|
|
259
|
+
} else {
|
|
260
|
+
return exist.value;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
match(key, props) {
|
|
264
|
+
const cacheRecord = this._find(key, props);
|
|
265
|
+
if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
|
|
266
|
+
this.delete(cacheRecord);
|
|
267
|
+
return void 0;
|
|
268
|
+
}
|
|
269
|
+
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
270
|
+
}
|
|
271
|
+
matchAll(key, props) {
|
|
272
|
+
const now = Date.now();
|
|
273
|
+
this.cache.forEach((item) => {
|
|
274
|
+
if (item.expirationTime && now > item.expirationTime) {
|
|
275
|
+
this.delete(item);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
if (key) {
|
|
279
|
+
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
280
|
+
}
|
|
281
|
+
return this.cache.map((x) => x.value);
|
|
282
|
+
}
|
|
283
|
+
delete(keyOrItem, props) {
|
|
284
|
+
const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
|
|
285
|
+
for (const item of itemsToDelete) {
|
|
286
|
+
const index = this.cache.indexOf(item);
|
|
287
|
+
if (index !== -1) {
|
|
288
|
+
this.cache.splice(index, 1);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
_find(key, props) {
|
|
293
|
+
return this.cache.find((x) => this._filter(x, key, props));
|
|
294
|
+
}
|
|
295
|
+
_filter(item, key, props) {
|
|
296
|
+
if (item.key !== key) return false;
|
|
297
|
+
if (!props) return true;
|
|
298
|
+
const itemProps = item.props;
|
|
299
|
+
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
__publicField$9(_Cache, "instance", {});
|
|
303
|
+
let Cache = _Cache;
|
|
304
|
+
|
|
66
305
|
var domain;
|
|
67
306
|
|
|
68
307
|
// This constructor is used to store event handlers. Instantiating this is
|
|
@@ -535,148 +774,9 @@ var NgwConnector = (function () {
|
|
|
535
774
|
return ret;
|
|
536
775
|
}
|
|
537
776
|
|
|
538
|
-
var __defProp$c = Object.defineProperty;
|
|
539
|
-
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
540
|
-
var __publicField$9 = (obj, key, value) => __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
541
|
-
const _Cache = class _Cache {
|
|
542
|
-
constructor(options = {}) {
|
|
543
|
-
__publicField$9(this, "cache", []);
|
|
544
|
-
var _a;
|
|
545
|
-
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
546
|
-
if (_Cache.instance[namespace]) {
|
|
547
|
-
return _Cache.instance[namespace];
|
|
548
|
-
}
|
|
549
|
-
_Cache.instance[namespace] = this;
|
|
550
|
-
return this;
|
|
551
|
-
}
|
|
552
|
-
clean() {
|
|
553
|
-
this.cache.length = 0;
|
|
554
|
-
}
|
|
555
|
-
all() {
|
|
556
|
-
return this.cache;
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Caching only a non-empty value.
|
|
560
|
-
*
|
|
561
|
-
* Useful for get or create strategy
|
|
562
|
-
* @example
|
|
563
|
-
* ```javascript
|
|
564
|
-
* const cache = new Cache();
|
|
565
|
-
* const getItemFunc = () => fetch(url).then((data) => {
|
|
566
|
-
* return data.json(); // undefined
|
|
567
|
-
* });
|
|
568
|
-
* const item = await cache.addFull('foo', getItemFunc);
|
|
569
|
-
* if (!item) {
|
|
570
|
-
* await createItem(); // 'New item'
|
|
571
|
-
* }
|
|
572
|
-
*
|
|
573
|
-
* // somewhere else in the code
|
|
574
|
-
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
575
|
-
* console.log(resp); // 'New item'
|
|
576
|
-
* });
|
|
577
|
-
* ```
|
|
578
|
-
*/
|
|
579
|
-
addFull(key, valueToSet, propsOrOptions, expirationTime) {
|
|
580
|
-
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
581
|
-
propsOrOptions.onlyFull = true;
|
|
582
|
-
}
|
|
583
|
-
return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
|
|
584
|
-
}
|
|
585
|
-
add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
|
|
586
|
-
let opt;
|
|
587
|
-
let props;
|
|
588
|
-
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
589
|
-
opt = propsOrOptions;
|
|
590
|
-
onlyFull = opt.onlyFull;
|
|
591
|
-
expirationTime = opt.expirationTime;
|
|
592
|
-
props = opt.props;
|
|
593
|
-
} else {
|
|
594
|
-
props = propsOrOptions;
|
|
595
|
-
}
|
|
596
|
-
const exist = this._find(key, props);
|
|
597
|
-
if (!exist) {
|
|
598
|
-
let value;
|
|
599
|
-
if (valueToSet instanceof Function) {
|
|
600
|
-
value = valueToSet();
|
|
601
|
-
} else {
|
|
602
|
-
value = valueToSet;
|
|
603
|
-
}
|
|
604
|
-
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
605
|
-
expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
|
|
606
|
-
const cacheItem = {
|
|
607
|
-
key,
|
|
608
|
-
value,
|
|
609
|
-
props: nonEmptyProps,
|
|
610
|
-
expirationTime
|
|
611
|
-
};
|
|
612
|
-
if (onlyFull && !full(value)) {
|
|
613
|
-
return value;
|
|
614
|
-
}
|
|
615
|
-
this.cache.push(cacheItem);
|
|
616
|
-
if (value instanceof Promise) {
|
|
617
|
-
value.catch((er) => {
|
|
618
|
-
this.delete(key, props);
|
|
619
|
-
});
|
|
620
|
-
if (onlyFull) {
|
|
621
|
-
value.then((x) => {
|
|
622
|
-
if (!full(x)) {
|
|
623
|
-
this.delete(key, props);
|
|
624
|
-
}
|
|
625
|
-
return x;
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
return value;
|
|
629
|
-
}
|
|
630
|
-
return value;
|
|
631
|
-
} else {
|
|
632
|
-
return exist.value;
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
match(key, props) {
|
|
636
|
-
const cacheRecord = this._find(key, props);
|
|
637
|
-
if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
|
|
638
|
-
this.delete(cacheRecord);
|
|
639
|
-
return void 0;
|
|
640
|
-
}
|
|
641
|
-
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
642
|
-
}
|
|
643
|
-
matchAll(key, props) {
|
|
644
|
-
const now = Date.now();
|
|
645
|
-
this.cache.forEach((item) => {
|
|
646
|
-
if (item.expirationTime && now > item.expirationTime) {
|
|
647
|
-
this.delete(item);
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
if (key) {
|
|
651
|
-
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
652
|
-
}
|
|
653
|
-
return this.cache.map((x) => x.value);
|
|
654
|
-
}
|
|
655
|
-
delete(keyOrItem, props) {
|
|
656
|
-
const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
|
|
657
|
-
for (const item of itemsToDelete) {
|
|
658
|
-
const index = this.cache.indexOf(item);
|
|
659
|
-
if (index !== -1) {
|
|
660
|
-
this.cache.splice(index, 1);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
_find(key, props) {
|
|
665
|
-
return this.cache.find((x) => this._filter(x, key, props));
|
|
666
|
-
}
|
|
667
|
-
_filter(item, key, props) {
|
|
668
|
-
if (item.key !== key) return false;
|
|
669
|
-
if (!props) return true;
|
|
670
|
-
const itemProps = item.props;
|
|
671
|
-
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
__publicField$9(_Cache, "instance", {});
|
|
675
|
-
let Cache = _Cache;
|
|
676
|
-
|
|
677
777
|
var pkg = {
|
|
678
778
|
name: "@nextgis/ngw-connector",
|
|
679
|
-
version: "3.0.0-alpha.
|
|
779
|
+
version: "3.0.0-alpha.13",
|
|
680
780
|
_priority: 12,
|
|
681
781
|
description: "A lightweight HTTP client optimized for use with NextGIS Web API",
|
|
682
782
|
main: "index.js",
|
|
@@ -685,15 +785,15 @@ var NgwConnector = (function () {
|
|
|
685
785
|
jsdelivr: "lib/ngw-connector.global.prod.js",
|
|
686
786
|
types: "lib/index.d.ts",
|
|
687
787
|
dependencies: {
|
|
688
|
-
"@nextgis/cache": "^3.0.0-alpha.
|
|
689
|
-
"@nextgis/cancelable-promise": "^3.0.0-alpha.
|
|
690
|
-
"@nextgis/utils": "^3.0.0-alpha.
|
|
788
|
+
"@nextgis/cache": "^3.0.0-alpha.13",
|
|
789
|
+
"@nextgis/cancelable-promise": "^3.0.0-alpha.13",
|
|
790
|
+
"@nextgis/utils": "^3.0.0-alpha.13",
|
|
691
791
|
"@types/events": "^3.0.0",
|
|
692
792
|
events: "*",
|
|
693
793
|
"form-data": "^4.0.0"
|
|
694
794
|
},
|
|
695
795
|
devDependencies: {
|
|
696
|
-
"@nextgis/build-tools": "^3.0.0-alpha.
|
|
796
|
+
"@nextgis/build-tools": "^3.0.0-alpha.13"
|
|
697
797
|
},
|
|
698
798
|
scripts: {
|
|
699
799
|
clean: "rimraf ./lib",
|
|
@@ -733,30 +833,6 @@ var NgwConnector = (function () {
|
|
|
733
833
|
gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
|
|
734
834
|
};
|
|
735
835
|
|
|
736
|
-
const CONNECTORS = [];
|
|
737
|
-
function addConnector(connector) {
|
|
738
|
-
CONNECTORS.push(connector);
|
|
739
|
-
}
|
|
740
|
-
function findConnector(options) {
|
|
741
|
-
return CONNECTORS.find((x) => {
|
|
742
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
743
|
-
if (options.auth) {
|
|
744
|
-
if (x.options.auth) {
|
|
745
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
746
|
-
}
|
|
747
|
-
} else {
|
|
748
|
-
return true;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
function removeConnector(connector) {
|
|
754
|
-
const index = CONNECTORS.indexOf(connector);
|
|
755
|
-
if (index !== -1) {
|
|
756
|
-
CONNECTORS.splice(index, 1);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
|
|
760
836
|
class AbortError extends Error {
|
|
761
837
|
constructor(message = "AbortError") {
|
|
762
838
|
super(message);
|
|
@@ -764,9 +840,9 @@ var NgwConnector = (function () {
|
|
|
764
840
|
}
|
|
765
841
|
}
|
|
766
842
|
|
|
767
|
-
var __defProp$
|
|
768
|
-
var __defNormalProp$
|
|
769
|
-
var __publicField$8 = (obj, key, value) => __defNormalProp$
|
|
843
|
+
var __defProp$a = Object.defineProperty;
|
|
844
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
845
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
770
846
|
class NgwError extends Error {
|
|
771
847
|
constructor(er) {
|
|
772
848
|
super();
|
|
@@ -783,9 +859,9 @@ var NgwConnector = (function () {
|
|
|
783
859
|
}
|
|
784
860
|
}
|
|
785
861
|
|
|
786
|
-
var __defProp$
|
|
787
|
-
var __defNormalProp$
|
|
788
|
-
var __publicField$7 = (obj, key, value) => __defNormalProp$
|
|
862
|
+
var __defProp$9 = Object.defineProperty;
|
|
863
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
864
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
789
865
|
class InsufficientPermissionsError extends NgwError {
|
|
790
866
|
constructor(obj) {
|
|
791
867
|
super(obj);
|
|
@@ -795,51 +871,19 @@ var NgwConnector = (function () {
|
|
|
795
871
|
}
|
|
796
872
|
}
|
|
797
873
|
|
|
798
|
-
var __defProp$9 = Object.defineProperty;
|
|
799
|
-
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
800
|
-
var __publicField$6 = (obj, key, value) => __defNormalProp$9(obj, key + "" , value);
|
|
801
|
-
class NetworkError extends Error {
|
|
802
|
-
constructor(url) {
|
|
803
|
-
super();
|
|
804
|
-
__publicField$6(this, "name", "NetworkError");
|
|
805
|
-
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
806
|
-
this.message = `Unable to request ${url}.
|
|
807
|
-
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
874
|
var __defProp$8 = Object.defineProperty;
|
|
812
875
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
813
|
-
var __publicField$
|
|
876
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
814
877
|
let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
|
|
815
878
|
constructor(obj) {
|
|
816
879
|
super(obj);
|
|
817
|
-
__publicField$
|
|
818
|
-
__publicField$
|
|
819
|
-
__publicField$
|
|
880
|
+
__publicField$6(this, "message", "There is no response from the server or problem connecting to server.");
|
|
881
|
+
__publicField$6(this, "title", "Network error");
|
|
882
|
+
__publicField$6(this, "detail", "Check network connectivity and try again later.");
|
|
820
883
|
Object.setPrototypeOf(this, NetworksResponseError.prototype);
|
|
821
884
|
}
|
|
822
885
|
};
|
|
823
886
|
|
|
824
|
-
var __defProp$7 = Object.defineProperty;
|
|
825
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
826
|
-
var __publicField$4 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
827
|
-
class ResourceNotFoundError extends NgwError {
|
|
828
|
-
constructor(obj) {
|
|
829
|
-
super(obj);
|
|
830
|
-
__publicField$4(this, "name", "ResourceNotFoundError");
|
|
831
|
-
__publicField$4(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
|
|
832
|
-
Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
function isError(error) {
|
|
837
|
-
if (isObject$1(error)) {
|
|
838
|
-
return error.status_code && error.exception && error.title;
|
|
839
|
-
}
|
|
840
|
-
return false;
|
|
841
|
-
}
|
|
842
|
-
|
|
843
887
|
function extractError(error) {
|
|
844
888
|
if (isObject$1(error)) {
|
|
845
889
|
if (error.name && error.message && error.title) {
|
|
@@ -865,6 +909,38 @@ var NgwConnector = (function () {
|
|
|
865
909
|
}
|
|
866
910
|
}
|
|
867
911
|
|
|
912
|
+
function isError(error) {
|
|
913
|
+
if (isObject$1(error)) {
|
|
914
|
+
return error.status_code && error.exception && error.title;
|
|
915
|
+
}
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
var __defProp$7 = Object.defineProperty;
|
|
920
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
921
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$7(obj, key + "" , value);
|
|
922
|
+
class NetworkError extends Error {
|
|
923
|
+
constructor(url) {
|
|
924
|
+
super();
|
|
925
|
+
__publicField$5(this, "name", "NetworkError");
|
|
926
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
927
|
+
this.message = `Unable to request ${url}.
|
|
928
|
+
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
var __defProp$6 = Object.defineProperty;
|
|
933
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
934
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
935
|
+
class ResourceNotFoundError extends NgwError {
|
|
936
|
+
constructor(obj) {
|
|
937
|
+
super(obj);
|
|
938
|
+
__publicField$4(this, "name", "ResourceNotFoundError");
|
|
939
|
+
__publicField$4(this, "exception", "nextgisweb.resource.exception.ResourceNotFound");
|
|
940
|
+
Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
868
944
|
var errors = /*#__PURE__*/Object.freeze({
|
|
869
945
|
__proto__: null,
|
|
870
946
|
AbortError: AbortError,
|
|
@@ -877,9 +953,9 @@ var NgwConnector = (function () {
|
|
|
877
953
|
isError: isError
|
|
878
954
|
});
|
|
879
955
|
|
|
880
|
-
var __defProp$
|
|
881
|
-
var __defNormalProp$
|
|
882
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$
|
|
956
|
+
var __defProp$5 = Object.defineProperty;
|
|
957
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
958
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
883
959
|
class BaseAPIError extends Error {
|
|
884
960
|
constructor(message) {
|
|
885
961
|
super(message || "Something went wrong.");
|
|
@@ -941,35 +1017,35 @@ var NgwConnector = (function () {
|
|
|
941
1017
|
}
|
|
942
1018
|
}
|
|
943
1019
|
|
|
944
|
-
var __defProp$
|
|
945
|
-
var __getOwnPropSymbols$
|
|
946
|
-
var __hasOwnProp$
|
|
947
|
-
var __propIsEnum$
|
|
948
|
-
var __defNormalProp$
|
|
949
|
-
var __spreadValues$
|
|
1020
|
+
var __defProp$4 = Object.defineProperty;
|
|
1021
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
1022
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
1023
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
1024
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1025
|
+
var __spreadValues$3 = (a, b) => {
|
|
950
1026
|
for (var prop in b || (b = {}))
|
|
951
|
-
if (__hasOwnProp$
|
|
952
|
-
__defNormalProp$
|
|
953
|
-
if (__getOwnPropSymbols$
|
|
954
|
-
for (var prop of __getOwnPropSymbols$
|
|
955
|
-
if (__propIsEnum$
|
|
956
|
-
__defNormalProp$
|
|
1027
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
1028
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
1029
|
+
if (__getOwnPropSymbols$3)
|
|
1030
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
1031
|
+
if (__propIsEnum$3.call(b, prop))
|
|
1032
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
957
1033
|
}
|
|
958
1034
|
return a;
|
|
959
1035
|
};
|
|
960
1036
|
var __objRest$2 = (source, exclude) => {
|
|
961
1037
|
var target = {};
|
|
962
1038
|
for (var prop in source)
|
|
963
|
-
if (__hasOwnProp$
|
|
1039
|
+
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
964
1040
|
target[prop] = source[prop];
|
|
965
|
-
if (source != null && __getOwnPropSymbols$
|
|
966
|
-
for (var prop of __getOwnPropSymbols$
|
|
967
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
1041
|
+
if (source != null && __getOwnPropSymbols$3)
|
|
1042
|
+
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
1043
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
968
1044
|
target[prop] = source[prop];
|
|
969
1045
|
}
|
|
970
1046
|
return target;
|
|
971
1047
|
};
|
|
972
|
-
var __async$
|
|
1048
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
973
1049
|
return new Promise((resolve, reject) => {
|
|
974
1050
|
var fulfilled = (value) => {
|
|
975
1051
|
try {
|
|
@@ -994,7 +1070,7 @@ var NgwConnector = (function () {
|
|
|
994
1070
|
return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
|
|
995
1071
|
}
|
|
996
1072
|
function responseJson(response) {
|
|
997
|
-
return __async$
|
|
1073
|
+
return __async$3(this, null, function* () {
|
|
998
1074
|
try {
|
|
999
1075
|
return response.json();
|
|
1000
1076
|
} catch (e) {
|
|
@@ -1003,7 +1079,7 @@ var NgwConnector = (function () {
|
|
|
1003
1079
|
});
|
|
1004
1080
|
}
|
|
1005
1081
|
function lunkwillResponseUrl(lwResp) {
|
|
1006
|
-
return __async$
|
|
1082
|
+
return __async$3(this, null, function* () {
|
|
1007
1083
|
const lwData = yield responseJson(lwResp);
|
|
1008
1084
|
let delay = lwData.delay_ms;
|
|
1009
1085
|
const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
|
|
@@ -1047,7 +1123,7 @@ var NgwConnector = (function () {
|
|
|
1047
1123
|
});
|
|
1048
1124
|
}
|
|
1049
1125
|
function lunkwillFetch(lwRespUrl) {
|
|
1050
|
-
return __async$
|
|
1126
|
+
return __async$3(this, null, function* () {
|
|
1051
1127
|
try {
|
|
1052
1128
|
return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
|
|
1053
1129
|
} catch (e) {
|
|
@@ -1095,14 +1171,14 @@ var NgwConnector = (function () {
|
|
|
1095
1171
|
return path + urlParams;
|
|
1096
1172
|
}
|
|
1097
1173
|
function request(path, options, cacheEngine) {
|
|
1098
|
-
return __async$
|
|
1174
|
+
return __async$3(this, null, function* () {
|
|
1099
1175
|
var _b;
|
|
1100
1176
|
const defaults = {
|
|
1101
1177
|
method: "GET",
|
|
1102
1178
|
credentials: "same-origin",
|
|
1103
1179
|
headers: {}
|
|
1104
1180
|
};
|
|
1105
|
-
const _a = __spreadValues$
|
|
1181
|
+
const _a = __spreadValues$3(__spreadValues$3({}, defaults), options), {
|
|
1106
1182
|
withCredentials,
|
|
1107
1183
|
responseType,
|
|
1108
1184
|
cacheProps,
|
|
@@ -1138,7 +1214,7 @@ var NgwConnector = (function () {
|
|
|
1138
1214
|
opt.headers = headers;
|
|
1139
1215
|
}
|
|
1140
1216
|
const url = generateUrl(path, query);
|
|
1141
|
-
const makeRequest = () => __async$
|
|
1217
|
+
const makeRequest = () => __async$3(this, null, function* () {
|
|
1142
1218
|
let response;
|
|
1143
1219
|
try {
|
|
1144
1220
|
response = yield fetch(url, opt);
|
|
@@ -1178,8 +1254,8 @@ var NgwConnector = (function () {
|
|
|
1178
1254
|
}
|
|
1179
1255
|
return body;
|
|
1180
1256
|
});
|
|
1181
|
-
if (cacheEngine && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
|
|
1182
|
-
const props = cacheProps ? cacheProps : __spreadValues$
|
|
1257
|
+
if (cacheEngine && cache !== false && ((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
|
|
1258
|
+
const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
|
|
1183
1259
|
withCredentials,
|
|
1184
1260
|
responseType
|
|
1185
1261
|
}));
|
|
@@ -1192,21 +1268,21 @@ var NgwConnector = (function () {
|
|
|
1192
1268
|
});
|
|
1193
1269
|
}
|
|
1194
1270
|
|
|
1195
|
-
var __defProp$
|
|
1271
|
+
var __defProp$3 = Object.defineProperty;
|
|
1196
1272
|
var __defProps$2 = Object.defineProperties;
|
|
1197
1273
|
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1198
|
-
var __getOwnPropSymbols$
|
|
1199
|
-
var __hasOwnProp$
|
|
1200
|
-
var __propIsEnum$
|
|
1201
|
-
var __defNormalProp$
|
|
1202
|
-
var __spreadValues$
|
|
1274
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
1275
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
1276
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
1277
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1278
|
+
var __spreadValues$2 = (a, b) => {
|
|
1203
1279
|
for (var prop in b || (b = {}))
|
|
1204
|
-
if (__hasOwnProp$
|
|
1205
|
-
__defNormalProp$
|
|
1206
|
-
if (__getOwnPropSymbols$
|
|
1207
|
-
for (var prop of __getOwnPropSymbols$
|
|
1208
|
-
if (__propIsEnum$
|
|
1209
|
-
__defNormalProp$
|
|
1280
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
1281
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1282
|
+
if (__getOwnPropSymbols$2)
|
|
1283
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
1284
|
+
if (__propIsEnum$2.call(b, prop))
|
|
1285
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1210
1286
|
}
|
|
1211
1287
|
return a;
|
|
1212
1288
|
};
|
|
@@ -1214,16 +1290,16 @@ var NgwConnector = (function () {
|
|
|
1214
1290
|
var __objRest$1 = (source, exclude) => {
|
|
1215
1291
|
var target = {};
|
|
1216
1292
|
for (var prop in source)
|
|
1217
|
-
if (__hasOwnProp$
|
|
1293
|
+
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1218
1294
|
target[prop] = source[prop];
|
|
1219
|
-
if (source != null && __getOwnPropSymbols$
|
|
1220
|
-
for (var prop of __getOwnPropSymbols$
|
|
1221
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
1295
|
+
if (source != null && __getOwnPropSymbols$2)
|
|
1296
|
+
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
1297
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
1222
1298
|
target[prop] = source[prop];
|
|
1223
1299
|
}
|
|
1224
1300
|
return target;
|
|
1225
1301
|
};
|
|
1226
|
-
var __async$
|
|
1302
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
1227
1303
|
return new Promise((resolve, reject) => {
|
|
1228
1304
|
var fulfilled = (value) => {
|
|
1229
1305
|
try {
|
|
@@ -1274,7 +1350,7 @@ var NgwConnector = (function () {
|
|
|
1274
1350
|
}
|
|
1275
1351
|
function route(name, connector, ...rest) {
|
|
1276
1352
|
const result = {
|
|
1277
|
-
url: (opt) => __async$
|
|
1353
|
+
url: (opt) => __async$2(this, null, function* () {
|
|
1278
1354
|
var _a;
|
|
1279
1355
|
const routeData = yield connector.connect();
|
|
1280
1356
|
const template = routeURL(
|
|
@@ -1288,27 +1364,32 @@ var NgwConnector = (function () {
|
|
|
1288
1364
|
};
|
|
1289
1365
|
const methods = ["get", "post", "put", "delete", "patch"];
|
|
1290
1366
|
for (const method of methods) {
|
|
1291
|
-
const methodResp = (requestOptions) =>
|
|
1367
|
+
const methodResp = (requestOptions) => {
|
|
1292
1368
|
var _b;
|
|
1293
1369
|
const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1370
|
+
if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
|
|
1371
|
+
throw new AbortError();
|
|
1372
|
+
}
|
|
1373
|
+
return connector.connect().then((routeData) => {
|
|
1374
|
+
var _a2;
|
|
1375
|
+
const template = routeURL(
|
|
1376
|
+
name,
|
|
1377
|
+
(_a2 = connector.options.baseUrl) != null ? _a2 : "",
|
|
1378
|
+
routeData,
|
|
1379
|
+
...rest
|
|
1380
|
+
);
|
|
1381
|
+
const headers = objectRemoveEmpty(__spreadValues$2(__spreadValues$2({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
|
|
1382
|
+
return request(
|
|
1383
|
+
template,
|
|
1384
|
+
__spreadProps$2(__spreadValues$2({
|
|
1385
|
+
headers
|
|
1386
|
+
}, restOpt), {
|
|
1387
|
+
method
|
|
1388
|
+
}),
|
|
1389
|
+
connector.cache
|
|
1390
|
+
);
|
|
1391
|
+
});
|
|
1392
|
+
};
|
|
1312
1393
|
result[method] = methodResp;
|
|
1313
1394
|
}
|
|
1314
1395
|
return result;
|
|
@@ -1330,7 +1411,7 @@ var NgwConnector = (function () {
|
|
|
1330
1411
|
const getResponseText = () => {
|
|
1331
1412
|
try {
|
|
1332
1413
|
return JSON.parse(xhr.responseText);
|
|
1333
|
-
} catch (
|
|
1414
|
+
} catch (e) {
|
|
1334
1415
|
return xhr.responseText;
|
|
1335
1416
|
}
|
|
1336
1417
|
};
|
|
@@ -1400,34 +1481,45 @@ var NgwConnector = (function () {
|
|
|
1400
1481
|
};
|
|
1401
1482
|
}
|
|
1402
1483
|
|
|
1403
|
-
const
|
|
1404
|
-
function
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1484
|
+
const CONNECTORS = [];
|
|
1485
|
+
function addConnector(connector) {
|
|
1486
|
+
CONNECTORS.push(connector);
|
|
1487
|
+
}
|
|
1488
|
+
function findConnector(options) {
|
|
1489
|
+
return CONNECTORS.find((x) => {
|
|
1490
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
1491
|
+
if (options.auth) {
|
|
1492
|
+
if (x.options.auth) {
|
|
1493
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
1494
|
+
}
|
|
1495
|
+
} else {
|
|
1496
|
+
return true;
|
|
1497
|
+
}
|
|
1411
1498
|
}
|
|
1412
|
-
return value;
|
|
1413
1499
|
});
|
|
1414
1500
|
}
|
|
1501
|
+
function removeConnector(connector) {
|
|
1502
|
+
const index = CONNECTORS.indexOf(connector);
|
|
1503
|
+
if (index !== -1) {
|
|
1504
|
+
CONNECTORS.splice(index, 1);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1415
1507
|
|
|
1416
|
-
var __defProp$
|
|
1508
|
+
var __defProp$2 = Object.defineProperty;
|
|
1417
1509
|
var __defProps$1 = Object.defineProperties;
|
|
1418
1510
|
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
1419
|
-
var __getOwnPropSymbols$
|
|
1420
|
-
var __hasOwnProp$
|
|
1421
|
-
var __propIsEnum$
|
|
1422
|
-
var __defNormalProp$
|
|
1423
|
-
var __spreadValues$
|
|
1511
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1512
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1513
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1514
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1515
|
+
var __spreadValues$1 = (a, b) => {
|
|
1424
1516
|
for (var prop in b || (b = {}))
|
|
1425
|
-
if (__hasOwnProp$
|
|
1426
|
-
__defNormalProp$
|
|
1427
|
-
if (__getOwnPropSymbols$
|
|
1428
|
-
for (var prop of __getOwnPropSymbols$
|
|
1429
|
-
if (__propIsEnum$
|
|
1430
|
-
__defNormalProp$
|
|
1517
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1518
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
1519
|
+
if (__getOwnPropSymbols$1)
|
|
1520
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1521
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1522
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
1431
1523
|
}
|
|
1432
1524
|
return a;
|
|
1433
1525
|
};
|
|
@@ -1435,17 +1527,17 @@ var NgwConnector = (function () {
|
|
|
1435
1527
|
var __objRest = (source, exclude) => {
|
|
1436
1528
|
var target = {};
|
|
1437
1529
|
for (var prop in source)
|
|
1438
|
-
if (__hasOwnProp$
|
|
1530
|
+
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1439
1531
|
target[prop] = source[prop];
|
|
1440
|
-
if (source != null && __getOwnPropSymbols$
|
|
1441
|
-
for (var prop of __getOwnPropSymbols$
|
|
1442
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
1532
|
+
if (source != null && __getOwnPropSymbols$1)
|
|
1533
|
+
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
1534
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
1443
1535
|
target[prop] = source[prop];
|
|
1444
1536
|
}
|
|
1445
1537
|
return target;
|
|
1446
1538
|
};
|
|
1447
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$
|
|
1448
|
-
var __async$
|
|
1539
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1540
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
1449
1541
|
return new Promise((resolve, reject) => {
|
|
1450
1542
|
var fulfilled = (value) => {
|
|
1451
1543
|
try {
|
|
@@ -1530,7 +1622,9 @@ var NgwConnector = (function () {
|
|
|
1530
1622
|
* ```
|
|
1531
1623
|
*/
|
|
1532
1624
|
connect() {
|
|
1533
|
-
return __async$
|
|
1625
|
+
return __async$1(this, arguments, function* ({
|
|
1626
|
+
signal
|
|
1627
|
+
} = {}) {
|
|
1534
1628
|
const auth = this.options.auth;
|
|
1535
1629
|
if (auth) {
|
|
1536
1630
|
const { login, password } = auth;
|
|
@@ -1539,11 +1633,12 @@ var NgwConnector = (function () {
|
|
|
1539
1633
|
}
|
|
1540
1634
|
}
|
|
1541
1635
|
const routeUrl = `${this.routeStr}?client=${this.client}`;
|
|
1542
|
-
return
|
|
1636
|
+
return this.makeQuery(
|
|
1543
1637
|
routeUrl,
|
|
1544
1638
|
{},
|
|
1545
1639
|
{
|
|
1546
1640
|
cacheName: "route",
|
|
1641
|
+
signal,
|
|
1547
1642
|
cache: true,
|
|
1548
1643
|
cacheProps: {
|
|
1549
1644
|
id: this.id,
|
|
@@ -1575,14 +1670,14 @@ var NgwConnector = (function () {
|
|
|
1575
1670
|
this.emitter.emit("logout");
|
|
1576
1671
|
}
|
|
1577
1672
|
getUserInfo(credentials, options) {
|
|
1578
|
-
return __async$
|
|
1673
|
+
return __async$1(this, null, function* () {
|
|
1579
1674
|
if (this.user && this.user.id) {
|
|
1580
1675
|
return this.user;
|
|
1581
1676
|
}
|
|
1582
1677
|
if (credentials) {
|
|
1583
1678
|
this.options.auth = credentials;
|
|
1584
1679
|
}
|
|
1585
|
-
const options_ = __spreadValues$
|
|
1680
|
+
const options_ = __spreadValues$1({
|
|
1586
1681
|
headers: this.getAuthorizationHeaders(credentials),
|
|
1587
1682
|
cache: true
|
|
1588
1683
|
}, options);
|
|
@@ -1623,7 +1718,7 @@ var NgwConnector = (function () {
|
|
|
1623
1718
|
this.activeRequests = {};
|
|
1624
1719
|
}
|
|
1625
1720
|
getActiveApiRequests() {
|
|
1626
|
-
return __spreadValues$
|
|
1721
|
+
return __spreadValues$1({}, this.activeRequests);
|
|
1627
1722
|
}
|
|
1628
1723
|
route(name, ...rest) {
|
|
1629
1724
|
return route(name, this, ...rest);
|
|
@@ -1635,7 +1730,7 @@ var NgwConnector = (function () {
|
|
|
1635
1730
|
* @param options - Request options
|
|
1636
1731
|
*/
|
|
1637
1732
|
makeQuery(_0, _1) {
|
|
1638
|
-
return __async$
|
|
1733
|
+
return __async$1(this, arguments, function* (url, params, options = {}) {
|
|
1639
1734
|
var _b;
|
|
1640
1735
|
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1641
1736
|
if (!url) {
|
|
@@ -1646,7 +1741,7 @@ var NgwConnector = (function () {
|
|
|
1646
1741
|
url = template(url, restParams);
|
|
1647
1742
|
}
|
|
1648
1743
|
url = encodeURI(fixUrlStr(url));
|
|
1649
|
-
options = __spreadValues$
|
|
1744
|
+
options = __spreadValues$1({ withCredentials: this.withCredentials }, options);
|
|
1650
1745
|
const {
|
|
1651
1746
|
cache,
|
|
1652
1747
|
signal: externalSignal,
|
|
@@ -1668,7 +1763,7 @@ var NgwConnector = (function () {
|
|
|
1668
1763
|
});
|
|
1669
1764
|
}
|
|
1670
1765
|
options.signal = internalSignal;
|
|
1671
|
-
const createPromise = () => __async$
|
|
1766
|
+
const createPromise = () => __async$1(this, null, function* () {
|
|
1672
1767
|
const id = REQUEST_ID++;
|
|
1673
1768
|
this.activeRequests[id] = internalAbortController;
|
|
1674
1769
|
try {
|
|
@@ -1678,7 +1773,7 @@ var NgwConnector = (function () {
|
|
|
1678
1773
|
}
|
|
1679
1774
|
});
|
|
1680
1775
|
if (method === "GET") {
|
|
1681
|
-
const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$
|
|
1776
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
|
|
1682
1777
|
headers,
|
|
1683
1778
|
withCredentials,
|
|
1684
1779
|
responseType,
|
|
@@ -1701,7 +1796,7 @@ var NgwConnector = (function () {
|
|
|
1701
1796
|
var _a;
|
|
1702
1797
|
if (this.user) {
|
|
1703
1798
|
options = options || {};
|
|
1704
|
-
options.headers = __spreadValues$
|
|
1799
|
+
options.headers = __spreadValues$1(__spreadValues$1({}, this.getAuthorizationHeaders()), options.headers);
|
|
1705
1800
|
}
|
|
1706
1801
|
if (this.requestTransform) {
|
|
1707
1802
|
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
@@ -1732,7 +1827,7 @@ var NgwConnector = (function () {
|
|
|
1732
1827
|
});
|
|
1733
1828
|
}
|
|
1734
1829
|
_login(credentials, options) {
|
|
1735
|
-
return __async$
|
|
1830
|
+
return __async$1(this, null, function* () {
|
|
1736
1831
|
try {
|
|
1737
1832
|
const data = yield this.getUserInfo(credentials, options);
|
|
1738
1833
|
this.user = data;
|
|
@@ -1790,27 +1885,27 @@ var NgwConnector = (function () {
|
|
|
1790
1885
|
return query;
|
|
1791
1886
|
}
|
|
1792
1887
|
|
|
1793
|
-
var __defProp$
|
|
1888
|
+
var __defProp$1 = Object.defineProperty;
|
|
1794
1889
|
var __defProps = Object.defineProperties;
|
|
1795
1890
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1796
|
-
var __getOwnPropSymbols
|
|
1797
|
-
var __hasOwnProp
|
|
1798
|
-
var __propIsEnum
|
|
1799
|
-
var __defNormalProp$
|
|
1800
|
-
var __spreadValues
|
|
1891
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1892
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1893
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1894
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1895
|
+
var __spreadValues = (a, b) => {
|
|
1801
1896
|
for (var prop in b || (b = {}))
|
|
1802
|
-
if (__hasOwnProp
|
|
1803
|
-
__defNormalProp$
|
|
1804
|
-
if (__getOwnPropSymbols
|
|
1805
|
-
for (var prop of __getOwnPropSymbols
|
|
1806
|
-
if (__propIsEnum
|
|
1807
|
-
__defNormalProp$
|
|
1897
|
+
if (__hasOwnProp.call(b, prop))
|
|
1898
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1899
|
+
if (__getOwnPropSymbols)
|
|
1900
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
1901
|
+
if (__propIsEnum.call(b, prop))
|
|
1902
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1808
1903
|
}
|
|
1809
1904
|
return a;
|
|
1810
1905
|
};
|
|
1811
1906
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1812
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$
|
|
1813
|
-
var __async
|
|
1907
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1908
|
+
var __async = (__this, __arguments, generator) => {
|
|
1814
1909
|
return new Promise((resolve, reject) => {
|
|
1815
1910
|
var fulfilled = (value) => {
|
|
1816
1911
|
try {
|
|
@@ -1851,7 +1946,7 @@ var NgwConnector = (function () {
|
|
|
1851
1946
|
* Fetching resource would be cached to speed up next call
|
|
1852
1947
|
*/
|
|
1853
1948
|
getOne(resource, requestOptions) {
|
|
1854
|
-
const opt = __spreadValues
|
|
1949
|
+
const opt = __spreadValues({}, requestOptions);
|
|
1855
1950
|
if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
|
|
1856
1951
|
if (resource.id !== void 0) {
|
|
1857
1952
|
resource.id;
|
|
@@ -1928,8 +2023,8 @@ var NgwConnector = (function () {
|
|
|
1928
2023
|
} else {
|
|
1929
2024
|
Object.assign(query, resourceToQuery(resource));
|
|
1930
2025
|
}
|
|
1931
|
-
return this.connector.route("resource.search").get(__spreadProps(__spreadValues
|
|
1932
|
-
query: __spreadValues
|
|
2026
|
+
return this.connector.route("resource.search").get(__spreadProps(__spreadValues({}, requestOptions), {
|
|
2027
|
+
query: __spreadValues({
|
|
1933
2028
|
serialization: "full"
|
|
1934
2029
|
}, query)
|
|
1935
2030
|
})).then((resources) => {
|
|
@@ -1982,7 +2077,7 @@ var NgwConnector = (function () {
|
|
|
1982
2077
|
});
|
|
1983
2078
|
}
|
|
1984
2079
|
_getChildrenOf(_0, _1) {
|
|
1985
|
-
return __async
|
|
2080
|
+
return __async(this, arguments, function* (parentDef, requestOptions, _items = []) {
|
|
1986
2081
|
let parent = void 0;
|
|
1987
2082
|
if (typeof parentDef === "string") {
|
|
1988
2083
|
parent = yield this.getId(parentDef, requestOptions);
|
|
@@ -1991,7 +2086,7 @@ var NgwConnector = (function () {
|
|
|
1991
2086
|
} else {
|
|
1992
2087
|
parent = parentDef;
|
|
1993
2088
|
}
|
|
1994
|
-
const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues
|
|
2089
|
+
const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues({}, requestOptions), {
|
|
1995
2090
|
query: {
|
|
1996
2091
|
parent
|
|
1997
2092
|
}
|
|
@@ -2019,7 +2114,7 @@ var NgwConnector = (function () {
|
|
|
2019
2114
|
});
|
|
2020
2115
|
}
|
|
2021
2116
|
_cleanResourceItemCache(id) {
|
|
2022
|
-
return __async
|
|
2117
|
+
return __async(this, null, function* () {
|
|
2023
2118
|
var _a;
|
|
2024
2119
|
const all = this.cache.all();
|
|
2025
2120
|
const toDelete = [];
|
|
@@ -2072,93 +2167,6 @@ var NgwConnector = (function () {
|
|
|
2072
2167
|
}
|
|
2073
2168
|
}
|
|
2074
2169
|
|
|
2075
|
-
var __defProp$1 = Object.defineProperty;
|
|
2076
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2077
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2078
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
2079
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2080
|
-
var __spreadValues = (a, b) => {
|
|
2081
|
-
for (var prop in b || (b = {}))
|
|
2082
|
-
if (__hasOwnProp.call(b, prop))
|
|
2083
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
2084
|
-
if (__getOwnPropSymbols)
|
|
2085
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
2086
|
-
if (__propIsEnum.call(b, prop))
|
|
2087
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
2088
|
-
}
|
|
2089
|
-
return a;
|
|
2090
|
-
};
|
|
2091
|
-
var __async = (__this, __arguments, generator) => {
|
|
2092
|
-
return new Promise((resolve, reject) => {
|
|
2093
|
-
var fulfilled = (value) => {
|
|
2094
|
-
try {
|
|
2095
|
-
step(generator.next(value));
|
|
2096
|
-
} catch (e) {
|
|
2097
|
-
reject(e);
|
|
2098
|
-
}
|
|
2099
|
-
};
|
|
2100
|
-
var rejected = (value) => {
|
|
2101
|
-
try {
|
|
2102
|
-
step(generator.throw(value));
|
|
2103
|
-
} catch (e) {
|
|
2104
|
-
reject(e);
|
|
2105
|
-
}
|
|
2106
|
-
};
|
|
2107
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2108
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
2109
|
-
});
|
|
2110
|
-
};
|
|
2111
|
-
function apiRequest(opt) {
|
|
2112
|
-
return __async(this, null, function* () {
|
|
2113
|
-
const { params, name, connector, requestOptions } = opt;
|
|
2114
|
-
const apiItems = yield connector.connect();
|
|
2115
|
-
let apiItem = apiItems && apiItems[name];
|
|
2116
|
-
if (apiItem) {
|
|
2117
|
-
apiItem = [...apiItem];
|
|
2118
|
-
let url = apiItem.shift();
|
|
2119
|
-
if (apiItem.length) {
|
|
2120
|
-
const replaceParams = {};
|
|
2121
|
-
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
2122
|
-
const arg = apiItem[fry];
|
|
2123
|
-
replaceParams[fry] = `{${arg}}`;
|
|
2124
|
-
if (params[arg] === void 0) {
|
|
2125
|
-
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
if (url) {
|
|
2129
|
-
url = template(url, replaceParams);
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
if (params) {
|
|
2133
|
-
const paramArray = [];
|
|
2134
|
-
const paramList = params.paramList;
|
|
2135
|
-
if (Array.isArray(paramList)) {
|
|
2136
|
-
paramList.forEach(([key, value]) => {
|
|
2137
|
-
paramArray.push(`${key}=${value}`);
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
for (const p in params) {
|
|
2141
|
-
if (apiItem.indexOf(p) === -1) {
|
|
2142
|
-
paramArray.push(`${p}=${params[p]}`);
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
if (paramArray.length) {
|
|
2146
|
-
url = `${url}?${paramArray.join("&")}`;
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
if (url) {
|
|
2150
|
-
return connector.makeQuery(url, params, __spreadValues({
|
|
2151
|
-
cacheName: name
|
|
2152
|
-
}, requestOptions));
|
|
2153
|
-
} else {
|
|
2154
|
-
throw new Error("Request URL is not set");
|
|
2155
|
-
}
|
|
2156
|
-
} else {
|
|
2157
|
-
return void 0;
|
|
2158
|
-
}
|
|
2159
|
-
});
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
2170
|
var __defProp = Object.defineProperty;
|
|
2163
2171
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2164
2172
|
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|