@nextgis/ngw-connector 3.0.0-alpha.13 → 3.0.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -3,12 +3,8 @@ import Cache from '@nextgis/cache';
3
3
  import { EventEmitter } from 'events';
4
4
  import { FeatureProperties, DeepPartial } from '@nextgis/utils';
5
5
  import { LegendSymbol } from '@nextgisweb/render/type/api';
6
- import { ResourceCls as ResourceCls$1, ResourceRead, CompositeRead } from '@nextgisweb/resource/type/api';
6
+ import { ResourceRead, CompositeRead } from '@nextgisweb/resource/type/api';
7
7
  import { GeoJsonObject, Geometry } from 'geojson';
8
- import { BasemapWebMapItemRead, BasemapWebMapRead } from '@nextgisweb/basemap/type/api';
9
- import { FeatureLayerRead } from '@nextgisweb/feature-layer/type/api';
10
- import { VectorLayerRead } from '@nextgisweb/vector-layer/type/api';
11
- import { WebMapRead } from '@nextgisweb/webmap/type/api';
12
8
 
13
9
  declare class LunkwillParam {
14
10
  static VALUES: (string | null)[];
@@ -594,7 +590,7 @@ interface Permission {
594
590
  propagate: boolean;
595
591
  }
596
592
  /** @deprecated use ResourceCls from '@nextgisweb/resource/type/api' instead */
597
- type ResourceCls = ResourceCls$1;
593
+ type ResourceCls = 'resource_group' | 'postgis_layer' | 'wmsserver_service' | 'basemap_layer' | 'postgis_connection' | 'webmap' | 'wfsserver_service' | 'vector_layer' | 'raster_layer' | 'mapserver_style' | 'qgis_vector_style' | 'qgis_raster_style' | 'raster_style' | 'file_bucket' | 'lookup_table' | 'wmsclient_layer' | 'wmsclient_connection' | 'formbuilder_form' | 'file_bucket' | 'svg_marker_library' | 'ogcfserver_service' | 'tmsclient_connection' | 'tileset' | 'collector_project' | 'demo_project' | 'trackers_group' | 'tracker' | 'terrain_provider' | 'model_3d' | 'tmsclient_layer';
598
594
  interface ResourceHierarchy {
599
595
  id: number;
600
596
  parent: {
@@ -602,7 +598,23 @@ interface ResourceHierarchy {
602
598
  };
603
599
  }
604
600
  /** @deprecated use ResourceRead from '@nextgisweb/resource/type/api' instead */
605
- type Resource = ResourceRead;
601
+ interface Resource {
602
+ cls: ResourceCls;
603
+ id: number;
604
+ parent: {
605
+ id: number;
606
+ };
607
+ owner_user: {
608
+ id: number;
609
+ };
610
+ permissions: Permission[];
611
+ keyname?: string | null;
612
+ display_name: string;
613
+ description?: string | null;
614
+ children: boolean;
615
+ interfaces: any[];
616
+ scopes: string[];
617
+ }
606
618
  interface BookmarkProperties {
607
619
  name: string;
608
620
  place: string;
@@ -619,7 +631,16 @@ interface NgwTimeFormat {
619
631
  }
620
632
  type NgwDateTimeFormat = NgwDateFormat & NgwTimeFormat;
621
633
  /** @deprecated use WebMapRead from '@nextgisweb/resource/type/api' instead */
622
- type WebmapResource = WebMapRead;
634
+ interface WebmapResource {
635
+ extent_left: number;
636
+ extent_right: number;
637
+ extent_bottom: number;
638
+ extent_top: number;
639
+ extent_constrained: boolean;
640
+ draw_order_enabled: boolean;
641
+ bookmark_resource: ResourceHierarchy;
642
+ root_item: TreeGroup;
643
+ }
623
644
  interface BasemapResource {
624
645
  url: string;
625
646
  /**
@@ -628,9 +649,17 @@ interface BasemapResource {
628
649
  qms: string;
629
650
  }
630
651
  /** @deprecated use BasemapWebMapItemRead from '@nextgisweb/resource/type/api' instead */
631
- type BasemapWebmapItem = BasemapWebMapItemRead;
652
+ interface BasemapWebmapItem {
653
+ resource_id: number;
654
+ display_name: string;
655
+ position?: number;
656
+ enabled?: boolean;
657
+ opacity?: number;
658
+ }
632
659
  /** @deprecated use BasemapWebMapRead from '@nextgisweb/resource/type/api' instead */
633
- type BasemapWebmap = BasemapWebMapRead;
660
+ interface BasemapWebmap {
661
+ basemaps: BasemapWebmapItem[];
662
+ }
634
663
  interface LookupTableResource {
635
664
  items: Record<string, string>;
636
665
  }
@@ -647,10 +676,17 @@ interface FeatureLayerField {
647
676
  typemod?: unknown;
648
677
  }
649
678
  /** @deprecated use FeatureLayerRead from '@nextgisweb/resource/type/api' instead */
650
- type FeatureResource = FeatureLayerRead;
679
+ interface FeatureResource {
680
+ fields: FeatureLayerField[];
681
+ }
651
682
  type GeometryType = 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'POINTZ' | 'LINESTRINGZ' | 'POLYGONZ' | 'MULTIPOINTZ' | 'MULTILINESTRINGZ' | 'MULTIPOLYGONZ';
652
683
  /** @deprecated use VectorLayerRead from '@nextgisweb/resource/type/api' instead */
653
- type VectorLayer = VectorLayerRead;
684
+ interface VectorLayer {
685
+ srs: {
686
+ id: number;
687
+ };
688
+ geometry_type: GeometryType;
689
+ }
654
690
  interface FileBucket {
655
691
  files: NgwFile[];
656
692
  tstamp?: any;
@@ -723,8 +759,28 @@ interface NgwFile {
723
759
  interface Resmeta {
724
760
  items: Record<string, any>;
725
761
  }
762
+ interface ResourceItemMain {
763
+ resource: Resource;
764
+ resmeta: Resmeta;
765
+ }
726
766
  /** @deprecated use CompositeRead from '@nextgisweb/resource/type/api' instead */
727
- type ResourceItem = CompositeRead;
767
+ interface ResourceItem extends ResourceItemMain {
768
+ [cls: string]: any;
769
+ webmap?: WebmapResource;
770
+ feature_layer?: FeatureResource;
771
+ vector_layer?: VectorLayer;
772
+ basemap_layer?: BasemapResource;
773
+ basemap_webmap?: BasemapWebmap;
774
+ lookup_table?: LookupTableResource;
775
+ file_bucket?: FileBucket;
776
+ wmsserver_service?: WmsServerService;
777
+ wmsclient_layer?: WmsClientLayer;
778
+ wmsclient_connection?: WmsClientConnection;
779
+ }
780
+ interface VectorLayerResourceItem extends ResourceItemMain {
781
+ vector_layer: VectorLayer;
782
+ feature_layer: FeatureResource;
783
+ }
728
784
 
729
785
  type ResourceStoreItemProperties = {
730
786
  [name: string]: any;
@@ -1072,6 +1128,7 @@ declare class NgwConnector {
1072
1128
  user?: UserInfo;
1073
1129
  cache: Cache;
1074
1130
  withCredentials?: boolean;
1131
+ private readonly routeCache;
1075
1132
  private client;
1076
1133
  private routeStr;
1077
1134
  private activeRequests;
@@ -1329,4 +1386,4 @@ interface LayerLegend {
1329
1386
  setSymbolRender?: (symbolIndex: number, status: boolean) => void;
1330
1387
  }
1331
1388
 
1332
- export { type ApiRouteParams, type BaseRequestOptions, type BasemapResource, type BasemapWebmap, type BasemapWebmapItem, type BookmarkProperties, type CreatedResource, type Credentials, type DeleteRequestItemsResponseMap, type DeleteRequestOptions, type FeatureItem, type FeatureItemAttachment, type FeatureItemExtensions, type FeatureItemToNgw, type FeatureLayerCount, type FeatureLayerField, type FeatureLayersIdentify, type FeatureLayersIdentifyItems, type FeatureResource, type FileBucket, type FileMeta, type FileUploadResp, type GeometryType, type GetChildrenOfOptions, type GetRequestItemsResponseMap, type GetRequestOptions, type GetRouteParam, type IdOnly, type KeysWithMethodAndPath, type KeysWithMethods, type KeysWithPaths, type LayerFeature, type LayerLegend, type LoadingQueue, type LookupTableResource, type LunkwillData, type Method, type MethodAvailable, type MethodRequestOptions, type NgwConnectorOptions, type NgwDateFormat, type NgwDateTimeFormat, type NgwExceptions, type NgwExtent, type NgwFile, type NgwLayerIdentifyError, type NgwTimeFormat, type Params, type PatchRequestItemsResponseMap, type PatchRequestOptions, type Permission, type PostRequestItemsResponseMap, type PostRequestOptions, type PutRequestItemsResponseMap, type PutRequestOptions, type PyramidRoute, type PyramidSettings, type PyramidSettingsPyramid, type PyramidSettingsPyramidCompanyLogo, type RequestHeaders, type RequestItemAdditionalParams, type RequestItemKeys, type RequestItemsParams, type RequestItemsParamsMap, type RequestItemsResponseMap, type RequestMethod, type RequestMethods, type RequestOptions, type RequestOptionsBody, type RequestOptionsByMethod, type RequestOptionsJSON, type RequestTransformFunction, type Resmeta, type Resource, type ResourceCls, type ResourceDefinition, type ResourceHierarchy, type ResourceIdKeynameDef, type ResourceItem, type ResourceItemDatatype, type ResourceStoreItem, type ResourceStoreItemDefault, type ResourceStoreItemProperties, type ResponseType, type RouteBody, type RouteMethods, type RouteName, type RouteParameters, type RouteQuery, type RouteRequestOptions, type RouteResp, type RouteResults, type Router, type SrsItem, type ToReturn, type TreeGroup, type TreeItem, type TreeLayer, type UserInfo, type VectorFieldDatatype, type VectorLayer, type WebmapResource, type WmsClientConnection, type WmsClientLayer, type WmsServerService, type WmsServerServiceLayer, NgwConnectorExtended as default };
1389
+ export { type ApiRouteParams, type BaseRequestOptions, type BasemapResource, type BasemapWebmap, type BasemapWebmapItem, type BookmarkProperties, type CreatedResource, type Credentials, type DeleteRequestItemsResponseMap, type DeleteRequestOptions, type FeatureItem, type FeatureItemAttachment, type FeatureItemExtensions, type FeatureItemToNgw, type FeatureLayerCount, type FeatureLayerField, type FeatureLayersIdentify, type FeatureLayersIdentifyItems, type FeatureResource, type FileBucket, type FileMeta, type FileUploadResp, type GeometryType, type GetChildrenOfOptions, type GetRequestItemsResponseMap, type GetRequestOptions, type GetRouteParam, type IdOnly, type KeysWithMethodAndPath, type KeysWithMethods, type KeysWithPaths, type LayerFeature, type LayerLegend, type LoadingQueue, type LookupTableResource, type LunkwillData, type Method, type MethodAvailable, type MethodRequestOptions, type NgwConnectorOptions, type NgwDateFormat, type NgwDateTimeFormat, type NgwExceptions, type NgwExtent, type NgwFile, type NgwLayerIdentifyError, type NgwTimeFormat, type Params, type PatchRequestItemsResponseMap, type PatchRequestOptions, type Permission, type PostRequestItemsResponseMap, type PostRequestOptions, type PutRequestItemsResponseMap, type PutRequestOptions, type PyramidRoute, type PyramidSettings, type PyramidSettingsPyramid, type PyramidSettingsPyramidCompanyLogo, type RequestHeaders, type RequestItemAdditionalParams, type RequestItemKeys, type RequestItemsParams, type RequestItemsParamsMap, type RequestItemsResponseMap, type RequestMethod, type RequestMethods, type RequestOptions, type RequestOptionsBody, type RequestOptionsByMethod, type RequestOptionsJSON, type RequestTransformFunction, type Resmeta, type Resource, type ResourceCls, type ResourceDefinition, type ResourceHierarchy, type ResourceIdKeynameDef, type ResourceItem, type ResourceItemDatatype, type ResourceItemMain, type ResourceStoreItem, type ResourceStoreItemDefault, type ResourceStoreItemProperties, type ResponseType, type RouteBody, type RouteMethods, type RouteName, type RouteParameters, type RouteQuery, type RouteRequestOptions, type RouteResp, type RouteResults, type Router, type SrsItem, type ToReturn, type TreeGroup, type TreeItem, type TreeLayer, type UserInfo, type VectorFieldDatatype, type VectorLayer, type VectorLayerResourceItem, type WebmapResource, type WmsClientConnection, type WmsClientLayer, type WmsServerService, type WmsServerServiceLayer, NgwConnectorExtended as default };
@@ -1,4 +1,4 @@
1
- /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.13; author: NextGIS */
1
+ /** Bundle of @nextgis/ngw-connector; version: 3.0.0-alpha.16; author: NextGIS */
2
2
  'use strict';
3
3
 
4
4
  var utils = require('@nextgis/utils');
@@ -70,7 +70,7 @@ async function apiRequest(opt) {
70
70
 
71
71
  var pkg = {
72
72
  name: "@nextgis/ngw-connector",
73
- version: "3.0.0-alpha.13",
73
+ version: "3.0.0-alpha.16",
74
74
  _priority: 12,
75
75
  description: "A lightweight HTTP client optimized for use with NextGIS Web API",
76
76
  main: "index.js",
@@ -411,7 +411,7 @@ function generateUrl(path, query) {
411
411
  return path + urlParams;
412
412
  }
413
413
  async function request(path, options, cacheEngine) {
414
- var _a;
414
+ var _a, _b;
415
415
  const defaults = {
416
416
  method: "GET",
417
417
  credentials: "same-origin",
@@ -431,6 +431,7 @@ async function request(path, options, cacheEngine) {
431
431
  ...defaults,
432
432
  ...options
433
433
  };
434
+ opt.method = (_a = opt.method) == null ? void 0 : _a.toUpperCase();
434
435
  if (withCredentials) {
435
436
  opt.credentials = "include";
436
437
  }
@@ -488,17 +489,26 @@ async function request(path, options, cacheEngine) {
488
489
  }
489
490
  return body;
490
491
  };
491
- if (cacheEngine && cache !== false && ((_a = opt.method) == null ? void 0 : _a.toUpperCase()) === "GET") {
492
- const props = cacheProps ? cacheProps : {
493
- ...utils.objectRemoveEmpty({
494
- withCredentials,
495
- responseType
496
- })
497
- };
498
- return cacheEngine.add(cacheName || url, makeRequest, {
499
- props,
500
- expirationTime: cache ? void 0 : 500
501
- });
492
+ if (cacheEngine) {
493
+ if (((_b = opt.method) == null ? void 0 : _b.toUpperCase()) === "GET") {
494
+ if (cache !== false) {
495
+ const props = cacheProps ? cacheProps : {
496
+ ...utils.objectRemoveEmpty({
497
+ withCredentials,
498
+ responseType
499
+ })
500
+ };
501
+ return cacheEngine.add(cacheName || url, makeRequest, {
502
+ props,
503
+ expirationTime: cache ? void 0 : 500
504
+ });
505
+ }
506
+ } else {
507
+ const ignoredForClean = ["api/feature_layer/identify"];
508
+ if (ignoredForClean.every((part) => !path.includes(part))) {
509
+ cacheEngine.clean();
510
+ }
511
+ }
502
512
  }
503
513
  return makeRequest();
504
514
  }
@@ -744,12 +754,16 @@ class NgwConnector {
744
754
  __publicField$2(this, "user");
745
755
  __publicField$2(this, "cache");
746
756
  __publicField$2(this, "withCredentials");
757
+ // Dedicated cache for route requests, as these are executed before any other requests.
758
+ // This cache does not need to be cleared during the session.
759
+ __publicField$2(this, "routeCache");
747
760
  __publicField$2(this, "client", `NextGIS-NGW-Connector/${pkg.version}`);
748
761
  __publicField$2(this, "routeStr", "/api/component/pyramid/route");
749
762
  __publicField$2(this, "activeRequests", {});
750
763
  __publicField$2(this, "requestTransform");
751
764
  const exist = findConnector(options);
752
765
  this.cache = new Cache({ namespace: options.cacheId });
766
+ this.routeCache = new Cache({ namespace: "routecache" });
753
767
  if (exist) {
754
768
  return exist;
755
769
  } else {
@@ -809,19 +823,9 @@ class NgwConnector {
809
823
  }
810
824
  }
811
825
  const routeUrl = `${this.routeStr}?client=${this.client}`;
812
- return this.makeQuery(
813
- routeUrl,
814
- {},
815
- {
816
- cacheName: "route",
817
- signal,
818
- cache: true,
819
- cacheProps: {
820
- id: this.id,
821
- auth,
822
- baseUrl: this.options.baseUrl
823
- }
824
- }
826
+ return this.routeCache.add(
827
+ this.options.baseUrl || String(this.id),
828
+ () => this.makeQuery(routeUrl, null, { signal, cache: false })
825
829
  );
826
830
  }
827
831
  /**
@@ -841,6 +845,7 @@ class NgwConnector {
841
845
  removeConnector(this);
842
846
  this.options.auth = void 0;
843
847
  this.user = void 0;
848
+ this.routeCache.clean();
844
849
  this.clearCache();
845
850
  this.emitter.emit("logout");
846
851
  }
@@ -945,7 +950,7 @@ class NgwConnector {
945
950
  this._cleanActiveRequest(id);
946
951
  }
947
952
  };
948
- if (method === "GET") {
953
+ if (method === "GET" && cache !== false) {
949
954
  const cacheOptions = cacheProps ? cacheProps : {
950
955
  ...utils.objectRemoveEmpty({
951
956
  headers,