@nextgis/ngw-connector 3.0.0-alpha.8 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -138
- package/lib/index.d.ts +154 -86
- package/lib/ngw-connector.cjs.js +286 -193
- 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 +543 -449
- 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 +402 -312
- 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 +543 -449
- 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.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 3.0.1; author: NextGIS */
|
|
2
2
|
var NgwConnector = (function () {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -55,10 +55,253 @@ var NgwConnector = (function () {
|
|
|
55
55
|
return newObj;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function isObject$1(val) {
|
|
59
|
+
return Object.prototype.toString.call(val) === "[object Object]";
|
|
60
|
+
}
|
|
61
|
+
|
|
58
62
|
function fixUrlStr(url) {
|
|
59
63
|
return url.replace(/([^:]\/)\/+/g, "$1");
|
|
60
64
|
}
|
|
61
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
|
+
|
|
62
305
|
var domain;
|
|
63
306
|
|
|
64
307
|
// This constructor is used to store event handlers. Instantiating this is
|
|
@@ -531,148 +774,9 @@ var NgwConnector = (function () {
|
|
|
531
774
|
return ret;
|
|
532
775
|
}
|
|
533
776
|
|
|
534
|
-
var __defProp$b = Object.defineProperty;
|
|
535
|
-
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
536
|
-
var __publicField$8 = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
537
|
-
const _Cache = class _Cache {
|
|
538
|
-
constructor(options = {}) {
|
|
539
|
-
__publicField$8(this, "cache", []);
|
|
540
|
-
var _a;
|
|
541
|
-
const namespace = (_a = options.namespace) != null ? _a : "default";
|
|
542
|
-
if (_Cache.instance[namespace]) {
|
|
543
|
-
return _Cache.instance[namespace];
|
|
544
|
-
}
|
|
545
|
-
_Cache.instance[namespace] = this;
|
|
546
|
-
return this;
|
|
547
|
-
}
|
|
548
|
-
clean() {
|
|
549
|
-
this.cache.length = 0;
|
|
550
|
-
}
|
|
551
|
-
all() {
|
|
552
|
-
return this.cache;
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
* Caching only a non-empty value.
|
|
556
|
-
*
|
|
557
|
-
* Useful for get or create strategy
|
|
558
|
-
* @example
|
|
559
|
-
* ```javascript
|
|
560
|
-
* const cache = new Cache();
|
|
561
|
-
* const getItemFunc = () => fetch(url).then((data) => {
|
|
562
|
-
* return data.json(); // undefined
|
|
563
|
-
* });
|
|
564
|
-
* const item = await cache.addFull('foo', getItemFunc);
|
|
565
|
-
* if (!item) {
|
|
566
|
-
* await createItem(); // 'New item'
|
|
567
|
-
* }
|
|
568
|
-
*
|
|
569
|
-
* // somewhere else in the code
|
|
570
|
-
* const item = await cache.addFull('foo', getItemFunc).then((resp) => {
|
|
571
|
-
* console.log(resp); // 'New item'
|
|
572
|
-
* });
|
|
573
|
-
* ```
|
|
574
|
-
*/
|
|
575
|
-
addFull(key, valueToSet, propsOrOptions, expirationTime) {
|
|
576
|
-
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
577
|
-
propsOrOptions.onlyFull = true;
|
|
578
|
-
}
|
|
579
|
-
return this.add(key, valueToSet, propsOrOptions, true, expirationTime);
|
|
580
|
-
}
|
|
581
|
-
add(key, valueToSet, propsOrOptions, onlyFull, expirationTime) {
|
|
582
|
-
let opt;
|
|
583
|
-
let props;
|
|
584
|
-
if (typeof propsOrOptions === "object" && "valueToSet" in propsOrOptions) {
|
|
585
|
-
opt = propsOrOptions;
|
|
586
|
-
onlyFull = opt.onlyFull;
|
|
587
|
-
expirationTime = opt.expirationTime;
|
|
588
|
-
props = opt.props;
|
|
589
|
-
} else {
|
|
590
|
-
props = propsOrOptions;
|
|
591
|
-
}
|
|
592
|
-
const exist = this._find(key, props);
|
|
593
|
-
if (!exist) {
|
|
594
|
-
let value;
|
|
595
|
-
if (valueToSet instanceof Function) {
|
|
596
|
-
value = valueToSet();
|
|
597
|
-
} else {
|
|
598
|
-
value = valueToSet;
|
|
599
|
-
}
|
|
600
|
-
const nonEmptyProps = props && JSON.parse(JSON.stringify(objectRemoveEmpty(props)));
|
|
601
|
-
expirationTime = expirationTime ? Date.now() + expirationTime : void 0;
|
|
602
|
-
const cacheItem = {
|
|
603
|
-
key,
|
|
604
|
-
value,
|
|
605
|
-
props: nonEmptyProps,
|
|
606
|
-
expirationTime
|
|
607
|
-
};
|
|
608
|
-
if (onlyFull && !full(value)) {
|
|
609
|
-
return value;
|
|
610
|
-
}
|
|
611
|
-
this.cache.push(cacheItem);
|
|
612
|
-
if (value instanceof Promise) {
|
|
613
|
-
value.catch((er) => {
|
|
614
|
-
this.delete(key, props);
|
|
615
|
-
});
|
|
616
|
-
if (onlyFull) {
|
|
617
|
-
value.then((x) => {
|
|
618
|
-
if (!full(x)) {
|
|
619
|
-
this.delete(key, props);
|
|
620
|
-
}
|
|
621
|
-
return x;
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
return value;
|
|
625
|
-
}
|
|
626
|
-
return value;
|
|
627
|
-
} else {
|
|
628
|
-
return exist.value;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
match(key, props) {
|
|
632
|
-
const cacheRecord = this._find(key, props);
|
|
633
|
-
if (cacheRecord && cacheRecord.expirationTime && Date.now() > cacheRecord.expirationTime) {
|
|
634
|
-
this.delete(cacheRecord);
|
|
635
|
-
return void 0;
|
|
636
|
-
}
|
|
637
|
-
return cacheRecord == null ? void 0 : cacheRecord.value;
|
|
638
|
-
}
|
|
639
|
-
matchAll(key, props) {
|
|
640
|
-
const now = Date.now();
|
|
641
|
-
this.cache.forEach((item) => {
|
|
642
|
-
if (item.expirationTime && now > item.expirationTime) {
|
|
643
|
-
this.delete(item);
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
if (key) {
|
|
647
|
-
return this.cache.filter((x) => this._filter(x, key, props)).map((x) => x.value);
|
|
648
|
-
}
|
|
649
|
-
return this.cache.map((x) => x.value);
|
|
650
|
-
}
|
|
651
|
-
delete(keyOrItem, props) {
|
|
652
|
-
const itemsToDelete = typeof keyOrItem === "string" ? this.cache.filter((x) => this._filter(x, keyOrItem, props)) : [keyOrItem];
|
|
653
|
-
for (const item of itemsToDelete) {
|
|
654
|
-
const index = this.cache.indexOf(item);
|
|
655
|
-
if (index !== -1) {
|
|
656
|
-
this.cache.splice(index, 1);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
_find(key, props) {
|
|
661
|
-
return this.cache.find((x) => this._filter(x, key, props));
|
|
662
|
-
}
|
|
663
|
-
_filter(item, key, props) {
|
|
664
|
-
if (item.key !== key) return false;
|
|
665
|
-
if (!props) return true;
|
|
666
|
-
const itemProps = item.props;
|
|
667
|
-
return objectDeepEqual(itemProps || {}, objectRemoveEmpty(props));
|
|
668
|
-
}
|
|
669
|
-
};
|
|
670
|
-
__publicField$8(_Cache, "instance", {});
|
|
671
|
-
let Cache = _Cache;
|
|
672
|
-
|
|
673
777
|
var pkg = {
|
|
674
778
|
name: "@nextgis/ngw-connector",
|
|
675
|
-
version: "3.0.
|
|
779
|
+
version: "3.0.1",
|
|
676
780
|
_priority: 12,
|
|
677
781
|
description: "A lightweight HTTP client optimized for use with NextGIS Web API",
|
|
678
782
|
main: "index.js",
|
|
@@ -681,15 +785,15 @@ var NgwConnector = (function () {
|
|
|
681
785
|
jsdelivr: "lib/ngw-connector.global.prod.js",
|
|
682
786
|
types: "lib/index.d.ts",
|
|
683
787
|
dependencies: {
|
|
684
|
-
"@nextgis/cache": "
|
|
685
|
-
"@nextgis/cancelable-promise": "
|
|
686
|
-
"@nextgis/utils": "
|
|
788
|
+
"@nextgis/cache": "3.0.0",
|
|
789
|
+
"@nextgis/cancelable-promise": "3.0.0",
|
|
790
|
+
"@nextgis/utils": "3.0.0",
|
|
687
791
|
"@types/events": "^3.0.0",
|
|
688
792
|
events: "*",
|
|
689
793
|
"form-data": "^4.0.0"
|
|
690
794
|
},
|
|
691
795
|
devDependencies: {
|
|
692
|
-
"@nextgis/build-tools": "
|
|
796
|
+
"@nextgis/build-tools": "3.0.0"
|
|
693
797
|
},
|
|
694
798
|
scripts: {
|
|
695
799
|
clean: "rimraf ./lib",
|
|
@@ -729,30 +833,6 @@ var NgwConnector = (function () {
|
|
|
729
833
|
gitHead: "edc68033f914f6c95c4125b9738bba6d36e990b4"
|
|
730
834
|
};
|
|
731
835
|
|
|
732
|
-
const CONNECTORS = [];
|
|
733
|
-
function addConnector(connector) {
|
|
734
|
-
CONNECTORS.push(connector);
|
|
735
|
-
}
|
|
736
|
-
function findConnector(options) {
|
|
737
|
-
return CONNECTORS.find((x) => {
|
|
738
|
-
if (x.options.baseUrl === options.baseUrl) {
|
|
739
|
-
if (options.auth) {
|
|
740
|
-
if (x.options.auth) {
|
|
741
|
-
return objectDeepEqual(x.options.auth, options.auth);
|
|
742
|
-
}
|
|
743
|
-
} else {
|
|
744
|
-
return true;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
function removeConnector(connector) {
|
|
750
|
-
const index = CONNECTORS.indexOf(connector);
|
|
751
|
-
if (index !== -1) {
|
|
752
|
-
CONNECTORS.splice(index, 1);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
836
|
class AbortError extends Error {
|
|
757
837
|
constructor(message = "AbortError") {
|
|
758
838
|
super(message);
|
|
@@ -762,18 +842,18 @@ var NgwConnector = (function () {
|
|
|
762
842
|
|
|
763
843
|
var __defProp$a = Object.defineProperty;
|
|
764
844
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
765
|
-
var __publicField$
|
|
845
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
766
846
|
class NgwError extends Error {
|
|
767
847
|
constructor(er) {
|
|
768
848
|
super();
|
|
769
|
-
__publicField$
|
|
770
|
-
__publicField$
|
|
771
|
-
__publicField$
|
|
772
|
-
__publicField$
|
|
773
|
-
__publicField$
|
|
774
|
-
__publicField$
|
|
775
|
-
__publicField$
|
|
776
|
-
__publicField$
|
|
849
|
+
__publicField$8(this, "name", "NgwError");
|
|
850
|
+
__publicField$8(this, "title");
|
|
851
|
+
__publicField$8(this, "message");
|
|
852
|
+
__publicField$8(this, "detail");
|
|
853
|
+
__publicField$8(this, "exception");
|
|
854
|
+
__publicField$8(this, "status_code");
|
|
855
|
+
__publicField$8(this, "data");
|
|
856
|
+
__publicField$8(this, "guru_meditation");
|
|
777
857
|
Object.assign(this, er);
|
|
778
858
|
Object.setPrototypeOf(this, NgwError.prototype);
|
|
779
859
|
}
|
|
@@ -781,35 +861,105 @@ var NgwConnector = (function () {
|
|
|
781
861
|
|
|
782
862
|
var __defProp$9 = Object.defineProperty;
|
|
783
863
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
784
|
-
var __publicField$
|
|
864
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
785
865
|
class InsufficientPermissionsError extends NgwError {
|
|
786
866
|
constructor(obj) {
|
|
787
867
|
super(obj);
|
|
788
|
-
__publicField$
|
|
789
|
-
__publicField$
|
|
868
|
+
__publicField$7(this, "name", "InsufficientPermissionsError");
|
|
869
|
+
__publicField$7(this, "exception", "nextgisweb.core.exception.InsufficientPermissions");
|
|
790
870
|
Object.setPrototypeOf(this, InsufficientPermissionsError.prototype);
|
|
791
871
|
}
|
|
792
872
|
}
|
|
793
873
|
|
|
794
874
|
var __defProp$8 = Object.defineProperty;
|
|
795
875
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
796
|
-
var __publicField$
|
|
797
|
-
class
|
|
876
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
877
|
+
let NetworksResponseError$1 = class NetworksResponseError extends NgwError {
|
|
798
878
|
constructor(obj) {
|
|
799
879
|
super(obj);
|
|
800
|
-
__publicField$
|
|
801
|
-
__publicField$
|
|
802
|
-
|
|
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.");
|
|
883
|
+
Object.setPrototypeOf(this, NetworksResponseError.prototype);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
function extractError(error) {
|
|
888
|
+
if (isObject$1(error)) {
|
|
889
|
+
if (error.name && error.message && error.title) {
|
|
890
|
+
return {
|
|
891
|
+
title: error.title,
|
|
892
|
+
message: error.message,
|
|
893
|
+
detail: error.detail || null,
|
|
894
|
+
data: error.data && error.data.data ? error.data.data : null
|
|
895
|
+
};
|
|
896
|
+
} else if (error.exception) {
|
|
897
|
+
if (error.status === void 0 || error.status === 0 || error.data === void 0) {
|
|
898
|
+
return new NetworksResponseError$1({
|
|
899
|
+
title: error.title,
|
|
900
|
+
status_code: error.status_code,
|
|
901
|
+
exception: error.exception
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return {
|
|
906
|
+
title: typeof error.title === "string" ? error.title : "Unexpected error",
|
|
907
|
+
message: typeof error.message === "string" ? error.message : "Something went wrong."
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function isError(error) {
|
|
913
|
+
if (isObject$1(error)) {
|
|
914
|
+
return error.status_code && error.exception && error.title;
|
|
803
915
|
}
|
|
916
|
+
return false;
|
|
804
917
|
}
|
|
805
918
|
|
|
806
919
|
var __defProp$7 = Object.defineProperty;
|
|
807
920
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
808
|
-
var __publicField$
|
|
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
|
+
|
|
944
|
+
var errors = /*#__PURE__*/Object.freeze({
|
|
945
|
+
__proto__: null,
|
|
946
|
+
AbortError: AbortError,
|
|
947
|
+
InsufficientPermissionsError: InsufficientPermissionsError,
|
|
948
|
+
NetworkError: NetworkError,
|
|
949
|
+
NetworksResponseError: NetworksResponseError$1,
|
|
950
|
+
NgwError: NgwError,
|
|
951
|
+
ResourceNotFoundError: ResourceNotFoundError,
|
|
952
|
+
extractError: extractError,
|
|
953
|
+
isError: isError
|
|
954
|
+
});
|
|
955
|
+
|
|
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);
|
|
809
959
|
class BaseAPIError extends Error {
|
|
810
960
|
constructor(message) {
|
|
811
961
|
super(message || "Something went wrong.");
|
|
812
|
-
__publicField$
|
|
962
|
+
__publicField$3(this, "title");
|
|
813
963
|
this.name = "BaseAPIError";
|
|
814
964
|
this.title = "Unknown API error";
|
|
815
965
|
if (Error.captureStackTrace) {
|
|
@@ -821,7 +971,7 @@ var NgwConnector = (function () {
|
|
|
821
971
|
// prettier-ignore
|
|
822
972
|
constructor(message) {
|
|
823
973
|
super(message || "There is no response from the server or problem connecting to server.");
|
|
824
|
-
__publicField$
|
|
974
|
+
__publicField$3(this, "detail");
|
|
825
975
|
this.title = "Network error";
|
|
826
976
|
this.detail = "Check network connectivity and try again later.";
|
|
827
977
|
}
|
|
@@ -835,8 +985,8 @@ var NgwConnector = (function () {
|
|
|
835
985
|
class ServerResponseError extends BaseAPIError {
|
|
836
986
|
constructor(data) {
|
|
837
987
|
super(data.message);
|
|
838
|
-
__publicField$
|
|
839
|
-
__publicField$
|
|
988
|
+
__publicField$3(this, "detail");
|
|
989
|
+
__publicField$3(this, "data");
|
|
840
990
|
this.title = data.title || this.title;
|
|
841
991
|
this.detail = data.detail || null;
|
|
842
992
|
this.data = data;
|
|
@@ -846,8 +996,8 @@ var NgwConnector = (function () {
|
|
|
846
996
|
// prettier-ignore
|
|
847
997
|
constructor(message, data = {}) {
|
|
848
998
|
super(message || "Unexpected error while processing long-running request.");
|
|
849
|
-
__publicField$
|
|
850
|
-
__publicField$
|
|
999
|
+
__publicField$3(this, "title");
|
|
1000
|
+
__publicField$3(this, "data");
|
|
851
1001
|
this.name = "LunkwillError";
|
|
852
1002
|
this.title = "Long-running request error";
|
|
853
1003
|
this.data = data;
|
|
@@ -867,35 +1017,35 @@ var NgwConnector = (function () {
|
|
|
867
1017
|
}
|
|
868
1018
|
}
|
|
869
1019
|
|
|
870
|
-
var __defProp$
|
|
871
|
-
var __getOwnPropSymbols$
|
|
872
|
-
var __hasOwnProp$
|
|
873
|
-
var __propIsEnum$
|
|
874
|
-
var __defNormalProp$
|
|
875
|
-
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) => {
|
|
876
1026
|
for (var prop in b || (b = {}))
|
|
877
|
-
if (__hasOwnProp$
|
|
878
|
-
__defNormalProp$
|
|
879
|
-
if (__getOwnPropSymbols$
|
|
880
|
-
for (var prop of __getOwnPropSymbols$
|
|
881
|
-
if (__propIsEnum$
|
|
882
|
-
__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]);
|
|
883
1033
|
}
|
|
884
1034
|
return a;
|
|
885
1035
|
};
|
|
886
1036
|
var __objRest$2 = (source, exclude) => {
|
|
887
1037
|
var target = {};
|
|
888
1038
|
for (var prop in source)
|
|
889
|
-
if (__hasOwnProp$
|
|
1039
|
+
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
890
1040
|
target[prop] = source[prop];
|
|
891
|
-
if (source != null && __getOwnPropSymbols$
|
|
892
|
-
for (var prop of __getOwnPropSymbols$
|
|
893
|
-
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))
|
|
894
1044
|
target[prop] = source[prop];
|
|
895
1045
|
}
|
|
896
1046
|
return target;
|
|
897
1047
|
};
|
|
898
|
-
var __async$
|
|
1048
|
+
var __async$3 = (__this, __arguments, generator) => {
|
|
899
1049
|
return new Promise((resolve, reject) => {
|
|
900
1050
|
var fulfilled = (value) => {
|
|
901
1051
|
try {
|
|
@@ -920,7 +1070,7 @@ var NgwConnector = (function () {
|
|
|
920
1070
|
return ct !== void 0 && ct !== null && ct.includes("application/vnd.lunkwill.request-summary+json");
|
|
921
1071
|
}
|
|
922
1072
|
function responseJson(response) {
|
|
923
|
-
return __async$
|
|
1073
|
+
return __async$3(this, null, function* () {
|
|
924
1074
|
try {
|
|
925
1075
|
return response.json();
|
|
926
1076
|
} catch (e) {
|
|
@@ -929,7 +1079,7 @@ var NgwConnector = (function () {
|
|
|
929
1079
|
});
|
|
930
1080
|
}
|
|
931
1081
|
function lunkwillResponseUrl(lwResp) {
|
|
932
|
-
return __async$
|
|
1082
|
+
return __async$3(this, null, function* () {
|
|
933
1083
|
const lwData = yield responseJson(lwResp);
|
|
934
1084
|
let delay = lwData.delay_ms;
|
|
935
1085
|
const retry = lwData.retry_ms !== void 0 ? lwData.retry_ms : 2e3;
|
|
@@ -973,7 +1123,7 @@ var NgwConnector = (function () {
|
|
|
973
1123
|
});
|
|
974
1124
|
}
|
|
975
1125
|
function lunkwillFetch(lwRespUrl) {
|
|
976
|
-
return __async$
|
|
1126
|
+
return __async$3(this, null, function* () {
|
|
977
1127
|
try {
|
|
978
1128
|
return yield window.fetch(lwRespUrl, { credentials: "same-origin" });
|
|
979
1129
|
} catch (e) {
|
|
@@ -1021,14 +1171,14 @@ var NgwConnector = (function () {
|
|
|
1021
1171
|
return path + urlParams;
|
|
1022
1172
|
}
|
|
1023
1173
|
function request(path, options, cacheEngine) {
|
|
1024
|
-
return __async$
|
|
1025
|
-
var _b;
|
|
1174
|
+
return __async$3(this, null, function* () {
|
|
1175
|
+
var _b, _c;
|
|
1026
1176
|
const defaults = {
|
|
1027
1177
|
method: "GET",
|
|
1028
1178
|
credentials: "same-origin",
|
|
1029
1179
|
headers: {}
|
|
1030
1180
|
};
|
|
1031
|
-
const _a = __spreadValues$
|
|
1181
|
+
const _a = __spreadValues$3(__spreadValues$3({}, defaults), options), {
|
|
1032
1182
|
withCredentials,
|
|
1033
1183
|
responseType,
|
|
1034
1184
|
cacheProps,
|
|
@@ -1047,6 +1197,7 @@ var NgwConnector = (function () {
|
|
|
1047
1197
|
"query",
|
|
1048
1198
|
"json"
|
|
1049
1199
|
]);
|
|
1200
|
+
opt.method = (_b = opt.method) == null ? void 0 : _b.toUpperCase();
|
|
1050
1201
|
if (withCredentials) {
|
|
1051
1202
|
opt.credentials = "include";
|
|
1052
1203
|
}
|
|
@@ -1064,12 +1215,12 @@ var NgwConnector = (function () {
|
|
|
1064
1215
|
opt.headers = headers;
|
|
1065
1216
|
}
|
|
1066
1217
|
const url = generateUrl(path, query);
|
|
1067
|
-
const makeRequest = () => __async$
|
|
1218
|
+
const makeRequest = () => __async$3(null, null, function* () {
|
|
1068
1219
|
let response;
|
|
1069
1220
|
try {
|
|
1070
1221
|
response = yield fetch(url, opt);
|
|
1071
1222
|
} catch (e) {
|
|
1072
|
-
if (
|
|
1223
|
+
if (opt.signal && opt.signal.aborted) {
|
|
1073
1224
|
throw e;
|
|
1074
1225
|
}
|
|
1075
1226
|
throw new NetworksResponseError();
|
|
@@ -1104,49 +1255,61 @@ var NgwConnector = (function () {
|
|
|
1104
1255
|
}
|
|
1105
1256
|
return body;
|
|
1106
1257
|
});
|
|
1107
|
-
if (cacheEngine
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1258
|
+
if (cacheEngine) {
|
|
1259
|
+
if (((_c = opt.method) == null ? void 0 : _c.toUpperCase()) === "GET") {
|
|
1260
|
+
if (cache !== false) {
|
|
1261
|
+
const props = cacheProps ? cacheProps : __spreadValues$3({}, objectRemoveEmpty({
|
|
1262
|
+
withCredentials,
|
|
1263
|
+
responseType
|
|
1264
|
+
}));
|
|
1265
|
+
return cacheEngine.add(cacheName || url, makeRequest, {
|
|
1266
|
+
props,
|
|
1267
|
+
expirationTime: cache ? void 0 : 500
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
} else {
|
|
1271
|
+
const ignoredForClean = ["api/feature_layer/identify"];
|
|
1272
|
+
if (ignoredForClean.every((part) => !path.includes(part))) {
|
|
1273
|
+
cacheEngine.clean();
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1113
1276
|
}
|
|
1114
1277
|
return makeRequest();
|
|
1115
1278
|
});
|
|
1116
1279
|
}
|
|
1117
1280
|
|
|
1118
|
-
var __defProp$
|
|
1119
|
-
var __defProps$
|
|
1120
|
-
var __getOwnPropDescs$
|
|
1121
|
-
var __getOwnPropSymbols$
|
|
1122
|
-
var __hasOwnProp$
|
|
1123
|
-
var __propIsEnum$
|
|
1124
|
-
var __defNormalProp$
|
|
1125
|
-
var __spreadValues$
|
|
1281
|
+
var __defProp$3 = Object.defineProperty;
|
|
1282
|
+
var __defProps$2 = Object.defineProperties;
|
|
1283
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
1284
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
1285
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
1286
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
1287
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1288
|
+
var __spreadValues$2 = (a, b) => {
|
|
1126
1289
|
for (var prop in b || (b = {}))
|
|
1127
|
-
if (__hasOwnProp$
|
|
1128
|
-
__defNormalProp$
|
|
1129
|
-
if (__getOwnPropSymbols$
|
|
1130
|
-
for (var prop of __getOwnPropSymbols$
|
|
1131
|
-
if (__propIsEnum$
|
|
1132
|
-
__defNormalProp$
|
|
1290
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
1291
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1292
|
+
if (__getOwnPropSymbols$2)
|
|
1293
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
1294
|
+
if (__propIsEnum$2.call(b, prop))
|
|
1295
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
1133
1296
|
}
|
|
1134
1297
|
return a;
|
|
1135
1298
|
};
|
|
1136
|
-
var __spreadProps$
|
|
1299
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
1137
1300
|
var __objRest$1 = (source, exclude) => {
|
|
1138
1301
|
var target = {};
|
|
1139
1302
|
for (var prop in source)
|
|
1140
|
-
if (__hasOwnProp$
|
|
1303
|
+
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1141
1304
|
target[prop] = source[prop];
|
|
1142
|
-
if (source != null && __getOwnPropSymbols$
|
|
1143
|
-
for (var prop of __getOwnPropSymbols$
|
|
1144
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
1305
|
+
if (source != null && __getOwnPropSymbols$2)
|
|
1306
|
+
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
1307
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
1145
1308
|
target[prop] = source[prop];
|
|
1146
1309
|
}
|
|
1147
1310
|
return target;
|
|
1148
1311
|
};
|
|
1149
|
-
var __async$
|
|
1312
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
1150
1313
|
return new Promise((resolve, reject) => {
|
|
1151
1314
|
var fulfilled = (value) => {
|
|
1152
1315
|
try {
|
|
@@ -1197,7 +1360,7 @@ var NgwConnector = (function () {
|
|
|
1197
1360
|
}
|
|
1198
1361
|
function route(name, connector, ...rest) {
|
|
1199
1362
|
const result = {
|
|
1200
|
-
url: (opt) => __async$
|
|
1363
|
+
url: (opt) => __async$2(null, null, function* () {
|
|
1201
1364
|
var _a;
|
|
1202
1365
|
const routeData = yield connector.connect();
|
|
1203
1366
|
const template = routeURL(
|
|
@@ -1211,45 +1374,37 @@ var NgwConnector = (function () {
|
|
|
1211
1374
|
};
|
|
1212
1375
|
const methods = ["get", "post", "put", "delete", "patch"];
|
|
1213
1376
|
for (const method of methods) {
|
|
1214
|
-
const methodResp = (requestOptions) =>
|
|
1377
|
+
const methodResp = (requestOptions) => {
|
|
1215
1378
|
var _b;
|
|
1216
1379
|
const _a = requestOptions || {}, { headers: optHeaders } = _a, restOpt = __objRest$1(_a, ["headers"]);
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1380
|
+
if ((_b = requestOptions == null ? void 0 : requestOptions.signal) == null ? void 0 : _b.aborted) {
|
|
1381
|
+
throw new AbortError();
|
|
1382
|
+
}
|
|
1383
|
+
return connector.connect().then((routeData) => {
|
|
1384
|
+
var _a2;
|
|
1385
|
+
const template = routeURL(
|
|
1386
|
+
name,
|
|
1387
|
+
(_a2 = connector.options.baseUrl) != null ? _a2 : "",
|
|
1388
|
+
routeData,
|
|
1389
|
+
...rest
|
|
1390
|
+
);
|
|
1391
|
+
const headers = objectRemoveEmpty(__spreadValues$2(__spreadValues$2({}, connector.getAuthorizationHeaders()), optHeaders != null ? optHeaders : {}));
|
|
1392
|
+
return request(
|
|
1393
|
+
template,
|
|
1394
|
+
__spreadProps$2(__spreadValues$2({
|
|
1395
|
+
headers
|
|
1396
|
+
}, restOpt), {
|
|
1397
|
+
method
|
|
1398
|
+
}),
|
|
1399
|
+
connector.cache
|
|
1400
|
+
);
|
|
1401
|
+
});
|
|
1402
|
+
};
|
|
1235
1403
|
result[method] = methodResp;
|
|
1236
1404
|
}
|
|
1237
1405
|
return result;
|
|
1238
1406
|
}
|
|
1239
1407
|
|
|
1240
|
-
var __defProp$4 = Object.defineProperty;
|
|
1241
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1242
|
-
var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
|
|
1243
|
-
class NetworkError extends Error {
|
|
1244
|
-
constructor(url) {
|
|
1245
|
-
super();
|
|
1246
|
-
__publicField$3(this, "name", "NetworkError");
|
|
1247
|
-
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
1248
|
-
this.message = `Unable to request ${url}.
|
|
1249
|
-
Possibly invalid NGW URL entered or CORS not configured to get request from ${location.origin}`;
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
1408
|
function isObject(val) {
|
|
1254
1409
|
return Object.prototype.toString.call(val) === "[object Object]";
|
|
1255
1410
|
}
|
|
@@ -1266,7 +1421,7 @@ var NgwConnector = (function () {
|
|
|
1266
1421
|
const getResponseText = () => {
|
|
1267
1422
|
try {
|
|
1268
1423
|
return JSON.parse(xhr.responseText);
|
|
1269
|
-
} catch (
|
|
1424
|
+
} catch (e) {
|
|
1270
1425
|
return xhr.responseText;
|
|
1271
1426
|
}
|
|
1272
1427
|
};
|
|
@@ -1336,52 +1491,63 @@ var NgwConnector = (function () {
|
|
|
1336
1491
|
};
|
|
1337
1492
|
}
|
|
1338
1493
|
|
|
1339
|
-
const
|
|
1340
|
-
function
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1494
|
+
const CONNECTORS = [];
|
|
1495
|
+
function addConnector(connector) {
|
|
1496
|
+
CONNECTORS.push(connector);
|
|
1497
|
+
}
|
|
1498
|
+
function findConnector(options) {
|
|
1499
|
+
return CONNECTORS.find((x) => {
|
|
1500
|
+
if (x.options.baseUrl === options.baseUrl) {
|
|
1501
|
+
if (options.auth) {
|
|
1502
|
+
if (x.options.auth) {
|
|
1503
|
+
return objectDeepEqual(x.options.auth, options.auth);
|
|
1504
|
+
}
|
|
1505
|
+
} else {
|
|
1506
|
+
return true;
|
|
1507
|
+
}
|
|
1347
1508
|
}
|
|
1348
|
-
return value;
|
|
1349
1509
|
});
|
|
1350
1510
|
}
|
|
1511
|
+
function removeConnector(connector) {
|
|
1512
|
+
const index = CONNECTORS.indexOf(connector);
|
|
1513
|
+
if (index !== -1) {
|
|
1514
|
+
CONNECTORS.splice(index, 1);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1351
1517
|
|
|
1352
|
-
var __defProp$
|
|
1353
|
-
var __defProps = Object.defineProperties;
|
|
1354
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1355
|
-
var __getOwnPropSymbols$
|
|
1356
|
-
var __hasOwnProp$
|
|
1357
|
-
var __propIsEnum$
|
|
1358
|
-
var __defNormalProp$
|
|
1359
|
-
var __spreadValues$
|
|
1518
|
+
var __defProp$2 = Object.defineProperty;
|
|
1519
|
+
var __defProps$1 = Object.defineProperties;
|
|
1520
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
1521
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1522
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1523
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1524
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1525
|
+
var __spreadValues$1 = (a, b) => {
|
|
1360
1526
|
for (var prop in b || (b = {}))
|
|
1361
|
-
if (__hasOwnProp$
|
|
1362
|
-
__defNormalProp$
|
|
1363
|
-
if (__getOwnPropSymbols$
|
|
1364
|
-
for (var prop of __getOwnPropSymbols$
|
|
1365
|
-
if (__propIsEnum$
|
|
1366
|
-
__defNormalProp$
|
|
1527
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1528
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
1529
|
+
if (__getOwnPropSymbols$1)
|
|
1530
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1531
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1532
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
1367
1533
|
}
|
|
1368
1534
|
return a;
|
|
1369
1535
|
};
|
|
1370
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1536
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1371
1537
|
var __objRest = (source, exclude) => {
|
|
1372
1538
|
var target = {};
|
|
1373
1539
|
for (var prop in source)
|
|
1374
|
-
if (__hasOwnProp$
|
|
1540
|
+
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1375
1541
|
target[prop] = source[prop];
|
|
1376
|
-
if (source != null && __getOwnPropSymbols$
|
|
1377
|
-
for (var prop of __getOwnPropSymbols$
|
|
1378
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
1542
|
+
if (source != null && __getOwnPropSymbols$1)
|
|
1543
|
+
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
1544
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
1379
1545
|
target[prop] = source[prop];
|
|
1380
1546
|
}
|
|
1381
1547
|
return target;
|
|
1382
1548
|
};
|
|
1383
|
-
var __publicField$2 = (obj, key, value) => __defNormalProp$
|
|
1384
|
-
var __async$
|
|
1549
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1550
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
1385
1551
|
return new Promise((resolve, reject) => {
|
|
1386
1552
|
var fulfilled = (value) => {
|
|
1387
1553
|
try {
|
|
@@ -1411,12 +1577,16 @@ var NgwConnector = (function () {
|
|
|
1411
1577
|
__publicField$2(this, "user");
|
|
1412
1578
|
__publicField$2(this, "cache");
|
|
1413
1579
|
__publicField$2(this, "withCredentials");
|
|
1580
|
+
// Dedicated cache for route requests, as these are executed before any other requests.
|
|
1581
|
+
// This cache does not need to be cleared during the session.
|
|
1582
|
+
__publicField$2(this, "routeCache");
|
|
1414
1583
|
__publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
|
|
1415
1584
|
__publicField$2(this, "routeStr", "/api/component/pyramid/route");
|
|
1416
1585
|
__publicField$2(this, "activeRequests", {});
|
|
1417
1586
|
__publicField$2(this, "requestTransform");
|
|
1418
1587
|
const exist = findConnector(options);
|
|
1419
1588
|
this.cache = new Cache({ namespace: options.cacheId });
|
|
1589
|
+
this.routeCache = new Cache({ namespace: "routecache" });
|
|
1420
1590
|
if (exist) {
|
|
1421
1591
|
return exist;
|
|
1422
1592
|
} else {
|
|
@@ -1466,7 +1636,9 @@ var NgwConnector = (function () {
|
|
|
1466
1636
|
* ```
|
|
1467
1637
|
*/
|
|
1468
1638
|
connect() {
|
|
1469
|
-
return __async$
|
|
1639
|
+
return __async$1(this, arguments, function* ({
|
|
1640
|
+
signal
|
|
1641
|
+
} = {}) {
|
|
1470
1642
|
const auth = this.options.auth;
|
|
1471
1643
|
if (auth) {
|
|
1472
1644
|
const { login, password } = auth;
|
|
@@ -1475,18 +1647,9 @@ var NgwConnector = (function () {
|
|
|
1475
1647
|
}
|
|
1476
1648
|
}
|
|
1477
1649
|
const routeUrl = `${this.routeStr}?client=${this.client}`;
|
|
1478
|
-
return
|
|
1479
|
-
|
|
1480
|
-
{}
|
|
1481
|
-
{
|
|
1482
|
-
cacheName: "route",
|
|
1483
|
-
cache: true,
|
|
1484
|
-
cacheProps: {
|
|
1485
|
-
id: this.id,
|
|
1486
|
-
auth,
|
|
1487
|
-
baseUrl: this.options.baseUrl
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1650
|
+
return this.routeCache.add(
|
|
1651
|
+
this.options.baseUrl || String(this.id),
|
|
1652
|
+
() => this.makeQuery(routeUrl, null, { signal, cache: false })
|
|
1490
1653
|
);
|
|
1491
1654
|
});
|
|
1492
1655
|
}
|
|
@@ -1507,18 +1670,19 @@ var NgwConnector = (function () {
|
|
|
1507
1670
|
removeConnector(this);
|
|
1508
1671
|
this.options.auth = void 0;
|
|
1509
1672
|
this.user = void 0;
|
|
1673
|
+
this.routeCache.clean();
|
|
1510
1674
|
this.clearCache();
|
|
1511
1675
|
this.emitter.emit("logout");
|
|
1512
1676
|
}
|
|
1513
1677
|
getUserInfo(credentials, options) {
|
|
1514
|
-
return __async$
|
|
1678
|
+
return __async$1(this, null, function* () {
|
|
1515
1679
|
if (this.user && this.user.id) {
|
|
1516
1680
|
return this.user;
|
|
1517
1681
|
}
|
|
1518
1682
|
if (credentials) {
|
|
1519
1683
|
this.options.auth = credentials;
|
|
1520
1684
|
}
|
|
1521
|
-
const options_ = __spreadValues$
|
|
1685
|
+
const options_ = __spreadValues$1({
|
|
1522
1686
|
headers: this.getAuthorizationHeaders(credentials),
|
|
1523
1687
|
cache: true
|
|
1524
1688
|
}, options);
|
|
@@ -1545,7 +1709,7 @@ var NgwConnector = (function () {
|
|
|
1545
1709
|
credentials = credentials || this.options.auth;
|
|
1546
1710
|
if (credentials) {
|
|
1547
1711
|
const { login, password } = credentials;
|
|
1548
|
-
const encodedStr =
|
|
1712
|
+
const encodedStr = `${login}:${password}`;
|
|
1549
1713
|
{
|
|
1550
1714
|
return window.btoa(encodedStr);
|
|
1551
1715
|
}
|
|
@@ -1559,7 +1723,7 @@ var NgwConnector = (function () {
|
|
|
1559
1723
|
this.activeRequests = {};
|
|
1560
1724
|
}
|
|
1561
1725
|
getActiveApiRequests() {
|
|
1562
|
-
return __spreadValues$
|
|
1726
|
+
return __spreadValues$1({}, this.activeRequests);
|
|
1563
1727
|
}
|
|
1564
1728
|
route(name, ...rest) {
|
|
1565
1729
|
return route(name, this, ...rest);
|
|
@@ -1571,7 +1735,7 @@ var NgwConnector = (function () {
|
|
|
1571
1735
|
* @param options - Request options
|
|
1572
1736
|
*/
|
|
1573
1737
|
makeQuery(_0, _1) {
|
|
1574
|
-
return __async$
|
|
1738
|
+
return __async$1(this, arguments, function* (url, params, options = {}) {
|
|
1575
1739
|
var _b;
|
|
1576
1740
|
url = (this.options.baseUrl ? this.options.baseUrl : "") + url;
|
|
1577
1741
|
if (!url) {
|
|
@@ -1582,7 +1746,7 @@ var NgwConnector = (function () {
|
|
|
1582
1746
|
url = template(url, restParams);
|
|
1583
1747
|
}
|
|
1584
1748
|
url = encodeURI(fixUrlStr(url));
|
|
1585
|
-
options = __spreadValues$
|
|
1749
|
+
options = __spreadValues$1({ withCredentials: this.withCredentials }, options);
|
|
1586
1750
|
const {
|
|
1587
1751
|
cache,
|
|
1588
1752
|
signal: externalSignal,
|
|
@@ -1604,7 +1768,7 @@ var NgwConnector = (function () {
|
|
|
1604
1768
|
});
|
|
1605
1769
|
}
|
|
1606
1770
|
options.signal = internalSignal;
|
|
1607
|
-
const createPromise = () => __async$
|
|
1771
|
+
const createPromise = () => __async$1(this, null, function* () {
|
|
1608
1772
|
const id = REQUEST_ID++;
|
|
1609
1773
|
this.activeRequests[id] = internalAbortController;
|
|
1610
1774
|
try {
|
|
@@ -1613,8 +1777,8 @@ var NgwConnector = (function () {
|
|
|
1613
1777
|
this._cleanActiveRequest(id);
|
|
1614
1778
|
}
|
|
1615
1779
|
});
|
|
1616
|
-
if (method === "GET") {
|
|
1617
|
-
const cacheOptions = cacheProps ? cacheProps : __spreadProps(__spreadValues$
|
|
1780
|
+
if (method === "GET" && cache !== false) {
|
|
1781
|
+
const cacheOptions = cacheProps ? cacheProps : __spreadProps$1(__spreadValues$1({}, objectRemoveEmpty({
|
|
1618
1782
|
headers,
|
|
1619
1783
|
withCredentials,
|
|
1620
1784
|
responseType,
|
|
@@ -1637,7 +1801,7 @@ var NgwConnector = (function () {
|
|
|
1637
1801
|
var _a;
|
|
1638
1802
|
if (this.user) {
|
|
1639
1803
|
options = options || {};
|
|
1640
|
-
options.headers = __spreadValues$
|
|
1804
|
+
options.headers = __spreadValues$1(__spreadValues$1({}, this.getAuthorizationHeaders()), options.headers);
|
|
1641
1805
|
}
|
|
1642
1806
|
if (this.requestTransform) {
|
|
1643
1807
|
const [transUrl, transOptions] = this.requestTransform(url, options);
|
|
@@ -1668,7 +1832,7 @@ var NgwConnector = (function () {
|
|
|
1668
1832
|
});
|
|
1669
1833
|
}
|
|
1670
1834
|
_login(credentials, options) {
|
|
1671
|
-
return __async$
|
|
1835
|
+
return __async$1(this, null, function* () {
|
|
1672
1836
|
try {
|
|
1673
1837
|
const data = yield this.getUserInfo(credentials, options);
|
|
1674
1838
|
this.user = data;
|
|
@@ -1696,10 +1860,7 @@ var NgwConnector = (function () {
|
|
|
1696
1860
|
return er;
|
|
1697
1861
|
}
|
|
1698
1862
|
}
|
|
1699
|
-
__publicField$2(NgwConnector, "errors",
|
|
1700
|
-
NgwError,
|
|
1701
|
-
ResourceNotFoundError
|
|
1702
|
-
});
|
|
1863
|
+
__publicField$2(NgwConnector, "errors", errors);
|
|
1703
1864
|
|
|
1704
1865
|
function resourceCompare(res1, res2) {
|
|
1705
1866
|
return objectDeepEqual(res1, res2);
|
|
@@ -1713,7 +1874,10 @@ var NgwConnector = (function () {
|
|
|
1713
1874
|
if (exclude.indexOf(key) === -1) {
|
|
1714
1875
|
if (isObject(value)) {
|
|
1715
1876
|
if (key === "owner_user") {
|
|
1716
|
-
const children = resourceToQuery(
|
|
1877
|
+
const children = resourceToQuery(
|
|
1878
|
+
value,
|
|
1879
|
+
key
|
|
1880
|
+
);
|
|
1717
1881
|
Object.assign(query, children);
|
|
1718
1882
|
} else if (key === "parent" && "id" in value) {
|
|
1719
1883
|
query.parent_id = value.id;
|
|
@@ -1726,24 +1890,27 @@ var NgwConnector = (function () {
|
|
|
1726
1890
|
return query;
|
|
1727
1891
|
}
|
|
1728
1892
|
|
|
1729
|
-
var __defProp$
|
|
1730
|
-
var
|
|
1731
|
-
var
|
|
1732
|
-
var
|
|
1733
|
-
var
|
|
1734
|
-
var
|
|
1893
|
+
var __defProp$1 = Object.defineProperty;
|
|
1894
|
+
var __defProps = Object.defineProperties;
|
|
1895
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
1896
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1897
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1898
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1899
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1900
|
+
var __spreadValues = (a, b) => {
|
|
1735
1901
|
for (var prop in b || (b = {}))
|
|
1736
|
-
if (__hasOwnProp
|
|
1737
|
-
__defNormalProp$
|
|
1738
|
-
if (__getOwnPropSymbols
|
|
1739
|
-
for (var prop of __getOwnPropSymbols
|
|
1740
|
-
if (__propIsEnum
|
|
1741
|
-
__defNormalProp$
|
|
1902
|
+
if (__hasOwnProp.call(b, prop))
|
|
1903
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1904
|
+
if (__getOwnPropSymbols)
|
|
1905
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
1906
|
+
if (__propIsEnum.call(b, prop))
|
|
1907
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
1742
1908
|
}
|
|
1743
1909
|
return a;
|
|
1744
1910
|
};
|
|
1745
|
-
var
|
|
1746
|
-
var
|
|
1911
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1912
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1913
|
+
var __async = (__this, __arguments, generator) => {
|
|
1747
1914
|
return new Promise((resolve, reject) => {
|
|
1748
1915
|
var fulfilled = (value) => {
|
|
1749
1916
|
try {
|
|
@@ -1784,7 +1951,7 @@ var NgwConnector = (function () {
|
|
|
1784
1951
|
* Fetching resource would be cached to speed up next call
|
|
1785
1952
|
*/
|
|
1786
1953
|
getOne(resource, requestOptions) {
|
|
1787
|
-
const opt = __spreadValues
|
|
1954
|
+
const opt = __spreadValues({}, requestOptions);
|
|
1788
1955
|
if (typeof resource === "string") ; else if (typeof resource === "number") ; else if (isObject(resource)) {
|
|
1789
1956
|
if (resource.id !== void 0) {
|
|
1790
1957
|
resource.id;
|
|
@@ -1861,9 +2028,11 @@ var NgwConnector = (function () {
|
|
|
1861
2028
|
} else {
|
|
1862
2029
|
Object.assign(query, resourceToQuery(resource));
|
|
1863
2030
|
}
|
|
1864
|
-
return this.connector.
|
|
1865
|
-
|
|
1866
|
-
|
|
2031
|
+
return this.connector.route("resource.search").get(__spreadProps(__spreadValues({}, requestOptions), {
|
|
2032
|
+
query: __spreadValues({
|
|
2033
|
+
serialization: "full"
|
|
2034
|
+
}, query)
|
|
2035
|
+
})).then((resources) => {
|
|
1867
2036
|
if ((requestOptions == null ? void 0 : requestOptions.cache) && resources) {
|
|
1868
2037
|
for (const x of resources) {
|
|
1869
2038
|
this.cache.add("resource.item", Promise.resolve(x), {
|
|
@@ -1879,7 +2048,8 @@ var NgwConnector = (function () {
|
|
|
1879
2048
|
}
|
|
1880
2049
|
getParent(resource, requestOptions) {
|
|
1881
2050
|
return this.getOne(resource, requestOptions).then((child) => {
|
|
1882
|
-
|
|
2051
|
+
var _a, _b;
|
|
2052
|
+
if ((_b = (_a = child == null ? void 0 : child.resource) == null ? void 0 : _a.parent) == null ? void 0 : _b.id) {
|
|
1883
2053
|
return this.getOne(child.resource.parent.id, requestOptions);
|
|
1884
2054
|
}
|
|
1885
2055
|
return Promise.resolve(void 0);
|
|
@@ -1911,10 +2081,21 @@ var NgwConnector = (function () {
|
|
|
1911
2081
|
}
|
|
1912
2082
|
});
|
|
1913
2083
|
}
|
|
1914
|
-
_getChildrenOf(
|
|
1915
|
-
return this
|
|
1916
|
-
parent
|
|
1917
|
-
|
|
2084
|
+
_getChildrenOf(_0, _1) {
|
|
2085
|
+
return __async(this, arguments, function* (parentDef, requestOptions, _items = []) {
|
|
2086
|
+
let parent = void 0;
|
|
2087
|
+
if (typeof parentDef === "string") {
|
|
2088
|
+
parent = yield this.getId(parentDef, requestOptions);
|
|
2089
|
+
} else if (typeof parentDef === "object") {
|
|
2090
|
+
parent = parentDef.id;
|
|
2091
|
+
} else {
|
|
2092
|
+
parent = parentDef;
|
|
2093
|
+
}
|
|
2094
|
+
const items = yield this.connector.route("resource.collection").get(__spreadProps(__spreadValues({}, requestOptions), {
|
|
2095
|
+
query: {
|
|
2096
|
+
parent
|
|
2097
|
+
}
|
|
2098
|
+
}));
|
|
1918
2099
|
const recursivePromises = [];
|
|
1919
2100
|
for (const item of items) {
|
|
1920
2101
|
if (requestOptions == null ? void 0 : requestOptions.cache) {
|
|
@@ -1938,7 +2119,7 @@ var NgwConnector = (function () {
|
|
|
1938
2119
|
});
|
|
1939
2120
|
}
|
|
1940
2121
|
_cleanResourceItemCache(id) {
|
|
1941
|
-
return __async
|
|
2122
|
+
return __async(this, null, function* () {
|
|
1942
2123
|
var _a;
|
|
1943
2124
|
const all = this.cache.all();
|
|
1944
2125
|
const toDelete = [];
|
|
@@ -1963,7 +2144,7 @@ var NgwConnector = (function () {
|
|
|
1963
2144
|
});
|
|
1964
2145
|
}
|
|
1965
2146
|
_fetchResourceById(id, requestOptions) {
|
|
1966
|
-
return this.connector.
|
|
2147
|
+
return this.connector.route("resource.item", { id }).get(requestOptions);
|
|
1967
2148
|
}
|
|
1968
2149
|
_fetchResourceBy(resource, requestOptions) {
|
|
1969
2150
|
return this.getMany(resource, requestOptions).then((resources) => {
|
|
@@ -1991,93 +2172,6 @@ var NgwConnector = (function () {
|
|
|
1991
2172
|
}
|
|
1992
2173
|
}
|
|
1993
2174
|
|
|
1994
|
-
var __defProp$1 = Object.defineProperty;
|
|
1995
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1996
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1997
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1998
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1999
|
-
var __spreadValues = (a, b) => {
|
|
2000
|
-
for (var prop in b || (b = {}))
|
|
2001
|
-
if (__hasOwnProp.call(b, prop))
|
|
2002
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
2003
|
-
if (__getOwnPropSymbols)
|
|
2004
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
2005
|
-
if (__propIsEnum.call(b, prop))
|
|
2006
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
2007
|
-
}
|
|
2008
|
-
return a;
|
|
2009
|
-
};
|
|
2010
|
-
var __async = (__this, __arguments, generator) => {
|
|
2011
|
-
return new Promise((resolve, reject) => {
|
|
2012
|
-
var fulfilled = (value) => {
|
|
2013
|
-
try {
|
|
2014
|
-
step(generator.next(value));
|
|
2015
|
-
} catch (e) {
|
|
2016
|
-
reject(e);
|
|
2017
|
-
}
|
|
2018
|
-
};
|
|
2019
|
-
var rejected = (value) => {
|
|
2020
|
-
try {
|
|
2021
|
-
step(generator.throw(value));
|
|
2022
|
-
} catch (e) {
|
|
2023
|
-
reject(e);
|
|
2024
|
-
}
|
|
2025
|
-
};
|
|
2026
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2027
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
2028
|
-
});
|
|
2029
|
-
};
|
|
2030
|
-
function apiRequest(opt) {
|
|
2031
|
-
return __async(this, null, function* () {
|
|
2032
|
-
const { params, name, connector, requestOptions } = opt;
|
|
2033
|
-
const apiItems = yield connector.connect();
|
|
2034
|
-
let apiItem = apiItems && apiItems[name];
|
|
2035
|
-
if (apiItem) {
|
|
2036
|
-
apiItem = [...apiItem];
|
|
2037
|
-
let url = apiItem.shift();
|
|
2038
|
-
if (apiItem.length) {
|
|
2039
|
-
const replaceParams = {};
|
|
2040
|
-
for (let fry = 0; fry < apiItem.length; fry++) {
|
|
2041
|
-
const arg = apiItem[fry];
|
|
2042
|
-
replaceParams[fry] = `{${arg}}`;
|
|
2043
|
-
if (params[arg] === void 0) {
|
|
2044
|
-
throw new Error(`\`${arg}\` URL API argument is not specified`);
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
if (url) {
|
|
2048
|
-
url = template(url, replaceParams);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
if (params) {
|
|
2052
|
-
const paramArray = [];
|
|
2053
|
-
const paramList = params.paramList;
|
|
2054
|
-
if (Array.isArray(paramList)) {
|
|
2055
|
-
paramList.forEach(([key, value]) => {
|
|
2056
|
-
paramArray.push(`${key}=${value}`);
|
|
2057
|
-
});
|
|
2058
|
-
}
|
|
2059
|
-
for (const p in params) {
|
|
2060
|
-
if (apiItem.indexOf(p) === -1) {
|
|
2061
|
-
paramArray.push(`${p}=${params[p]}`);
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
if (paramArray.length) {
|
|
2065
|
-
url = `${url}?${paramArray.join("&")}`;
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
if (url) {
|
|
2069
|
-
return connector.makeQuery(url, params, __spreadValues({
|
|
2070
|
-
cacheName: name
|
|
2071
|
-
}, requestOptions));
|
|
2072
|
-
} else {
|
|
2073
|
-
throw new Error("Request URL is not set");
|
|
2074
|
-
}
|
|
2075
|
-
} else {
|
|
2076
|
-
return void 0;
|
|
2077
|
-
}
|
|
2078
|
-
});
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
2175
|
var __defProp = Object.defineProperty;
|
|
2082
2176
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2083
2177
|
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|