@nextgis/ngw-connector 1.12.0 → 1.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -3
- package/lib/index.d.ts +27 -14
- package/lib/ngw-connector.cjs.js +84 -20
- 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 +84 -31
- 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 +84 -31
- 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 +84 -31
- 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 +5 -5
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
if (process.env.NODE_ENV === '
|
|
4
|
-
module.exports = require('./lib/ngw-connector.cjs.prod.js');
|
|
5
|
-
} else {
|
|
3
|
+
if (process.env.NODE_ENV === 'development') {
|
|
6
4
|
module.exports = require('./lib/ngw-connector.cjs.js');
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require('./lib/ngw-connector.cjs.prod.js');
|
|
7
7
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -128,6 +128,10 @@ export declare interface FileUploadResp {
|
|
|
128
128
|
|
|
129
129
|
export declare type GeometryType = 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'POINTZ' | 'LINESTRINGZ' | 'POLYGONZ' | 'MULTIPOINTZ' | 'MULTILINESTRINGZ' | 'MULTIPOLYGONZ';
|
|
130
130
|
|
|
131
|
+
export declare interface GetChildrenOfOptions extends Pick<RequestOptions, 'cache'> {
|
|
132
|
+
recursive?: boolean;
|
|
133
|
+
}
|
|
134
|
+
|
|
131
135
|
export declare interface GetRequestItemsResponseMap extends RequestItemKeys {
|
|
132
136
|
'pyramid.route': PyramidRoute;
|
|
133
137
|
'pyramid.settings': PyramidSettings;
|
|
@@ -184,6 +188,7 @@ declare class NgwConnector {
|
|
|
184
188
|
user?: UserInfo;
|
|
185
189
|
resources: ResourcesControl;
|
|
186
190
|
private routeStr;
|
|
191
|
+
private activeRequests;
|
|
187
192
|
constructor(options: NgwConnectorOptions);
|
|
188
193
|
static create(options: NgwConnectorOptions): NgwConnector;
|
|
189
194
|
/**
|
|
@@ -221,6 +226,9 @@ declare class NgwConnector {
|
|
|
221
226
|
*/
|
|
222
227
|
getAuthorizationHeaders(credentials?: Credentials): RequestHeaders | undefined;
|
|
223
228
|
makeClientId(credentials?: Credentials): string | undefined;
|
|
229
|
+
/** Stop all api requests */
|
|
230
|
+
abort(): void;
|
|
231
|
+
getActiveApiRequests(): CancelablePromise<any>[];
|
|
224
232
|
/**
|
|
225
233
|
* Send request to NGW api router.
|
|
226
234
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -303,11 +311,11 @@ declare class NgwConnector {
|
|
|
303
311
|
/**
|
|
304
312
|
* {@inheritDoc ResourcesControl.getOne}
|
|
305
313
|
*/
|
|
306
|
-
getResource(resource: ResourceDefinition, requestOptions?:
|
|
314
|
+
getResource(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<ResourceItem | undefined>;
|
|
307
315
|
/**
|
|
308
316
|
* {@inheritDoc ResourcesControl.getOneOrFail}
|
|
309
317
|
*/
|
|
310
|
-
getResourceOrFail(resource: ResourceDefinition, requestOptions?:
|
|
318
|
+
getResourceOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<ResourceItem>;
|
|
311
319
|
/**
|
|
312
320
|
* @deprecated - use {@link NgwConnector.getResource}
|
|
313
321
|
*/
|
|
@@ -323,23 +331,23 @@ declare class NgwConnector {
|
|
|
323
331
|
/**
|
|
324
332
|
* {@inheritDoc ResourcesControl.getId}
|
|
325
333
|
*/
|
|
326
|
-
getResourceId(resource: ResourceDefinition, requestOptions?:
|
|
334
|
+
getResourceId(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<number | undefined>;
|
|
327
335
|
/**
|
|
328
336
|
* {@inheritDoc ResourcesControl.getIdOrFail}
|
|
329
337
|
*/
|
|
330
|
-
getResourceIdOrFail(resource: ResourceDefinition, requestOptions?:
|
|
338
|
+
getResourceIdOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<number>;
|
|
331
339
|
/**
|
|
332
340
|
* {@inheritDoc ResourcesControl.getMany}
|
|
333
341
|
*/
|
|
334
|
-
getResourcesBy(resource: DeepPartial<Resource>, requestOptions?:
|
|
342
|
+
getResourcesBy(resource: DeepPartial<Resource>, requestOptions?: RequestOptions): CancelablePromise<ResourceItem[]>;
|
|
335
343
|
/**
|
|
336
344
|
* {@inheritDoc ResourcesControl.getParent}
|
|
337
345
|
*/
|
|
338
|
-
getResourceParent(resource: ResourceDefinition, requestOptions?:
|
|
346
|
+
getResourceParent(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<ResourceItem | undefined>;
|
|
339
347
|
/**
|
|
340
348
|
* {@inheritDoc ResourcesControl.getChildrenOf}
|
|
341
349
|
*/
|
|
342
|
-
getResourceChildren(resource: ResourceDefinition, requestOptions?:
|
|
350
|
+
getResourceChildren(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): CancelablePromise<ResourceItem[]>;
|
|
343
351
|
/**
|
|
344
352
|
* {@inheritDoc ResourcesControl.update}
|
|
345
353
|
*/
|
|
@@ -349,6 +357,7 @@ declare class NgwConnector {
|
|
|
349
357
|
*/
|
|
350
358
|
deleteResource(resource: ResourceIdKeynameDef): CancelablePromise<void>;
|
|
351
359
|
/* Excluded from this release type: _loadData */
|
|
360
|
+
private _cleanActiveRequests;
|
|
352
361
|
private _handleHttpError;
|
|
353
362
|
}
|
|
354
363
|
export default NgwConnector;
|
|
@@ -379,7 +388,7 @@ declare class NgwError extends Error {
|
|
|
379
388
|
status_code: number | 404 | 500;
|
|
380
389
|
data?: Record<string, any>;
|
|
381
390
|
guru_meditation: string;
|
|
382
|
-
constructor(er?: NgwError);
|
|
391
|
+
constructor(er?: Partial<NgwError>);
|
|
383
392
|
}
|
|
384
393
|
|
|
385
394
|
export declare type NgwExceptions = 'nextgisweb.resource.exception.ResourceNotFound' | 'nextgisweb.core.exception.InsufficientPermissions';
|
|
@@ -681,6 +690,7 @@ export declare interface RequestOptions<M = RequestMethods> {
|
|
|
681
690
|
withCredentials?: boolean;
|
|
682
691
|
responseType?: 'json' | 'blob';
|
|
683
692
|
cache?: boolean;
|
|
693
|
+
signal?: AbortSignal;
|
|
684
694
|
onProgress?: (percentComplete: number, event: ProgressEvent) => void;
|
|
685
695
|
}
|
|
686
696
|
|
|
@@ -764,7 +774,7 @@ declare class ResourcesControl {
|
|
|
764
774
|
* Fetching resource would be cached to speed up next call
|
|
765
775
|
*/
|
|
766
776
|
getOne(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<ResourceItem | undefined>;
|
|
767
|
-
getOneOrFail(resource: ResourceDefinition, requestOptions?:
|
|
777
|
+
getOneOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<ResourceItem>;
|
|
768
778
|
/**
|
|
769
779
|
* A fast way to retrieve resource ID for any resource definition.
|
|
770
780
|
* @param resource - Any available resource definition
|
|
@@ -775,7 +785,7 @@ declare class ResourcesControl {
|
|
|
775
785
|
* then this method will come in handy to facilitate the extraction of the identifier
|
|
776
786
|
* if the resource is specified through a keyname or other parameters.
|
|
777
787
|
*/
|
|
778
|
-
getId(resource: ResourceDefinition, requestOptions?:
|
|
788
|
+
getId(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<number | undefined>;
|
|
779
789
|
/**
|
|
780
790
|
* A fast way to retrieve resource ID for any resource definition.
|
|
781
791
|
* @param resource - Any available resource definition
|
|
@@ -784,10 +794,11 @@ declare class ResourcesControl {
|
|
|
784
794
|
* Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
|
|
785
795
|
* To not make one more checks if the resource is definitely exists
|
|
786
796
|
*/
|
|
787
|
-
getIdOrFail(resource: ResourceDefinition, requestOptions?:
|
|
797
|
+
getIdOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<number>;
|
|
788
798
|
getMany(resource: DeepPartial<Resource>, requestOptions?: RequestOptions): CancelablePromise<ResourceItem[]>;
|
|
789
|
-
getParent(resource: ResourceDefinition, requestOptions?:
|
|
790
|
-
getChildrenOf(resource: ResourceDefinition, requestOptions?:
|
|
799
|
+
getParent(resource: ResourceDefinition, requestOptions?: RequestOptions): CancelablePromise<ResourceItem | undefined>;
|
|
800
|
+
getChildrenOf(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): CancelablePromise<ResourceItem[]>;
|
|
801
|
+
private _getChildrenOf;
|
|
791
802
|
update(resource: ResourceDefinition, data: DeepPartial<ResourceItem>): CancelablePromise<ResourceItem | undefined>;
|
|
792
803
|
/**
|
|
793
804
|
* Fast way to delete resource from NGW and clean cache.
|
|
@@ -800,7 +811,9 @@ declare class ResourcesControl {
|
|
|
800
811
|
private _resourceCacheFilter;
|
|
801
812
|
}
|
|
802
813
|
|
|
803
|
-
export declare type ResourceStoreItem<P extends ResourceStoreItemProperties = ResourceStoreItemProperties> = ResourceStoreItemDefault &
|
|
814
|
+
export declare type ResourceStoreItem<P extends ResourceStoreItemProperties = ResourceStoreItemProperties> = ResourceStoreItemDefault & {
|
|
815
|
+
data?: string;
|
|
816
|
+
} & P;
|
|
804
817
|
|
|
805
818
|
export declare interface ResourceStoreItemDefault {
|
|
806
819
|
[field: string]: string | number | boolean | null | Date;
|
package/lib/ngw-connector.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-connector; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/ngw-connector; version: 1.13.5; author: NextGIS */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var events = require('events');
|
|
@@ -128,6 +128,13 @@ var NgwError = /** @class */ (function (_super) {
|
|
|
128
128
|
return NgwError;
|
|
129
129
|
}(Error));
|
|
130
130
|
|
|
131
|
+
function isError(error) {
|
|
132
|
+
if (utils.isObject(error)) {
|
|
133
|
+
return error.status_code && error.exception && error.title;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
131
138
|
function isObject(val) {
|
|
132
139
|
return Object.prototype.toString.call(val) === '[object Object]';
|
|
133
140
|
}
|
|
@@ -182,7 +189,7 @@ var loadData;
|
|
|
182
189
|
}
|
|
183
190
|
Object.assign(requestOpt.headers, __assign({}, form.getHeaders()));
|
|
184
191
|
}
|
|
185
|
-
if (body !== undefined
|
|
192
|
+
if (body !== undefined) {
|
|
186
193
|
Object.assign(requestOpt.headers, {
|
|
187
194
|
'content-type': 'application/json',
|
|
188
195
|
'content-length': Buffer.byteLength(body),
|
|
@@ -208,10 +215,14 @@ var loadData;
|
|
|
208
215
|
}
|
|
209
216
|
catch (er) {
|
|
210
217
|
reject(er);
|
|
211
|
-
// throw new Error(er);
|
|
212
218
|
}
|
|
213
219
|
if (json !== undefined) {
|
|
214
|
-
|
|
220
|
+
if (isError(json)) {
|
|
221
|
+
reject('extractError(json)');
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
resolve(json);
|
|
225
|
+
}
|
|
215
226
|
}
|
|
216
227
|
}
|
|
217
228
|
}
|
|
@@ -391,7 +402,12 @@ var ResourcesControl = /** @class */ (function () {
|
|
|
391
402
|
forCache.id = resource;
|
|
392
403
|
}
|
|
393
404
|
else if (isObject(resource)) {
|
|
394
|
-
|
|
405
|
+
if (resource.id !== undefined) {
|
|
406
|
+
forCache.id = resource.id;
|
|
407
|
+
}
|
|
408
|
+
else if (resource.keyname) {
|
|
409
|
+
forCache.keyname = resource.keyname;
|
|
410
|
+
}
|
|
395
411
|
}
|
|
396
412
|
var makeRequest = function () {
|
|
397
413
|
if (typeof resource === 'string') {
|
|
@@ -493,20 +509,35 @@ var ResourcesControl = /** @class */ (function () {
|
|
|
493
509
|
};
|
|
494
510
|
ResourcesControl.prototype.getChildrenOf = function (resource, requestOptions) {
|
|
495
511
|
var _this = this;
|
|
496
|
-
return this.
|
|
497
|
-
return _this.
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
512
|
+
return this.getIdOrFail(resource).then(function (parent) {
|
|
513
|
+
return _this._getChildrenOf(parent, requestOptions);
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
ResourcesControl.prototype._getChildrenOf = function (parent, requestOptions, _items) {
|
|
517
|
+
var _this = this;
|
|
518
|
+
if (_items === void 0) { _items = []; }
|
|
519
|
+
return this.connector
|
|
520
|
+
.get('resource.collection', __assign({ cache: true }, requestOptions), {
|
|
521
|
+
parent: parent,
|
|
522
|
+
})
|
|
523
|
+
.then(function (items) {
|
|
524
|
+
var recursivePromises = [];
|
|
525
|
+
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
|
526
|
+
var item = items_1[_i];
|
|
527
|
+
_this.cache.add('resource.item', CancelablePromise__default.resolve(item), {
|
|
528
|
+
id: item.resource.id,
|
|
529
|
+
});
|
|
530
|
+
_items.push(item);
|
|
531
|
+
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.recursive) && item.resource.children) {
|
|
532
|
+
recursivePromises.push(_this._getChildrenOf(item.resource.id, requestOptions, _items));
|
|
507
533
|
}
|
|
508
|
-
|
|
509
|
-
|
|
534
|
+
}
|
|
535
|
+
if (recursivePromises.length) {
|
|
536
|
+
return CancelablePromise__default.all(recursivePromises).then(function () {
|
|
537
|
+
return _items;
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
return _items;
|
|
510
541
|
});
|
|
511
542
|
};
|
|
512
543
|
ResourcesControl.prototype.update = function (resource, data) {
|
|
@@ -680,6 +711,7 @@ var NgwConnector$1 = /** @class */ (function () {
|
|
|
680
711
|
this.id = ID++;
|
|
681
712
|
this.emitter = new events.EventEmitter();
|
|
682
713
|
this.routeStr = '/api/component/pyramid/route';
|
|
714
|
+
this.activeRequests = [];
|
|
683
715
|
var exist = findConnector(options);
|
|
684
716
|
if (exist) {
|
|
685
717
|
return exist;
|
|
@@ -765,6 +797,7 @@ var NgwConnector$1 = /** @class */ (function () {
|
|
|
765
797
|
* Disconnecting a user. Aborting all current requests
|
|
766
798
|
*/
|
|
767
799
|
NgwConnector.prototype.logout = function () {
|
|
800
|
+
this.abort();
|
|
768
801
|
removeConnector(this);
|
|
769
802
|
this.options.auth = undefined;
|
|
770
803
|
this.user = undefined;
|
|
@@ -817,6 +850,17 @@ var NgwConnector$1 = /** @class */ (function () {
|
|
|
817
850
|
}
|
|
818
851
|
}
|
|
819
852
|
};
|
|
853
|
+
/** Stop all api requests */
|
|
854
|
+
NgwConnector.prototype.abort = function () {
|
|
855
|
+
for (var _i = 0, _a = this.activeRequests; _i < _a.length; _i++) {
|
|
856
|
+
var req = _a[_i];
|
|
857
|
+
req.cancel();
|
|
858
|
+
}
|
|
859
|
+
this.activeRequests = [];
|
|
860
|
+
};
|
|
861
|
+
NgwConnector.prototype.getActiveApiRequests = function () {
|
|
862
|
+
return __spreadArray([], this.activeRequests, true);
|
|
863
|
+
};
|
|
820
864
|
/**
|
|
821
865
|
* Send request to NGW api router.
|
|
822
866
|
* @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
|
|
@@ -1031,14 +1075,20 @@ var NgwConnector$1 = /** @class */ (function () {
|
|
|
1031
1075
|
NgwConnector.prototype._loadData = function (url, options) {
|
|
1032
1076
|
var _this = this;
|
|
1033
1077
|
options.responseType = options.responseType || 'json';
|
|
1034
|
-
|
|
1078
|
+
var request = new CancelablePromise__default(function (resolve, reject, onCancel) {
|
|
1035
1079
|
if (_this.user) {
|
|
1036
1080
|
options = options || {};
|
|
1037
1081
|
// options.withCredentials = true;
|
|
1038
1082
|
options.headers = __assign(__assign({}, _this.getAuthorizationHeaders()), options.headers);
|
|
1039
1083
|
}
|
|
1040
1084
|
loadData(url, resolve, options, reject, onCancel);
|
|
1041
|
-
})
|
|
1085
|
+
})
|
|
1086
|
+
.then(function (resp) {
|
|
1087
|
+
_this._cleanActiveRequests(request);
|
|
1088
|
+
return resp;
|
|
1089
|
+
})
|
|
1090
|
+
.catch(function (httpError) {
|
|
1091
|
+
_this._cleanActiveRequests(request);
|
|
1042
1092
|
if (httpError instanceof CancelablePromise__default.CancelError) ;
|
|
1043
1093
|
else {
|
|
1044
1094
|
// @ts-ignore
|
|
@@ -1051,6 +1101,20 @@ var NgwConnector$1 = /** @class */ (function () {
|
|
|
1051
1101
|
}
|
|
1052
1102
|
}
|
|
1053
1103
|
});
|
|
1104
|
+
if (options.signal &&
|
|
1105
|
+
typeof options.signal.addEventListener === 'function') {
|
|
1106
|
+
options.signal.addEventListener('abort', function () {
|
|
1107
|
+
request.cancel();
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
this.activeRequests.push(request);
|
|
1111
|
+
return request;
|
|
1112
|
+
};
|
|
1113
|
+
NgwConnector.prototype._cleanActiveRequests = function (request) {
|
|
1114
|
+
var activeRequestIndex = this.activeRequests.indexOf(request);
|
|
1115
|
+
if (activeRequestIndex !== -1) {
|
|
1116
|
+
this.activeRequests.splice(activeRequestIndex, 1);
|
|
1117
|
+
}
|
|
1054
1118
|
};
|
|
1055
1119
|
NgwConnector.prototype._handleHttpError = function (er) {
|
|
1056
1120
|
if (er) {
|