@nextgis/ngw-connector 3.0.0-alpha.0 → 3.0.0-alpha.12

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
@@ -1,8 +1,121 @@
1
- /// <reference types="node" />
1
+ import { Routes } from '@nextgisweb/pyramid/type/route';
2
2
  import { EventEmitter } from 'events';
3
3
  import Cache from '@nextgis/cache';
4
4
  import { FeatureProperties, DeepPartial } from '@nextgis/utils';
5
5
  import { GeoJsonObject, Geometry } from 'geojson';
6
+ import { LegendSymbol } from '@nextgisweb/render/type/api';
7
+ import { ResourceRead, CompositeRead } from '@nextgisweb/resource/type/api';
8
+
9
+ declare class LunkwillParam {
10
+ static VALUES: (string | null)[];
11
+ private value;
12
+ constructor();
13
+ update(value: string | null, cond?: boolean): void;
14
+ suggest(cond?: boolean): void;
15
+ require(cond?: boolean): void;
16
+ toHeaders(headers: Record<string, string>): void;
17
+ }
18
+
19
+ type RouteParameters = {
20
+ [K in keyof Routes]: Routes[K]['pathArr'] | [Routes[K]['pathObj']];
21
+ };
22
+ type RouteName = keyof Routes;
23
+ type GetRouteParam<R extends RouteName> = (RouteParameters[R] & [
24
+ object
25
+ ])[0];
26
+ type RequestMethod = keyof RouteMethods<RouteName>;
27
+ type Method = RequestMethod | Uppercase<RequestMethod>;
28
+ type ResponseType = 'blob' | 'json';
29
+ interface RouteRequestOptions<RT extends ResponseType = 'json', ReturnUrl extends boolean = false, Q = any, B = string | null | boolean | Record<string, any> | any[]> extends Omit<RequestInit, 'cache'> {
30
+ headers?: Record<string, string>;
31
+ cache?: boolean;
32
+ query?: Q;
33
+ json?: B;
34
+ /** Has lower priority than the json */
35
+ body?: string;
36
+ /**
37
+ * The type of data that the server will respond with.
38
+ * Can be either 'json' or 'blob'.
39
+ */
40
+ responseType?: RT;
41
+ /**
42
+ * @deprecated use {@link RequestInit.credential}
43
+ * Indicates whether to include credentials such as cookies, authentication headers,
44
+ * or TLS client certificates in cross-site Access-Control requests.
45
+ */
46
+ withCredentials?: boolean;
47
+ /**
48
+ * Name to use for caching the request.
49
+ */
50
+ cacheName?: string;
51
+ /**
52
+ * Properties to override default cache behavior.
53
+ */
54
+ cacheProps?: Record<string, unknown>;
55
+ lunkwill?: LunkwillParam;
56
+ lunkwillReturnUrl?: ReturnUrl;
57
+ }
58
+ interface GetRequestOptions<Q = any, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> extends Omit<RouteRequestOptions<RT, ReturnUrl, Q>, 'json' | 'body'> {
59
+ method?: 'GET';
60
+ }
61
+ interface RequestOptionsJSON<Q = any, B = string | null | boolean | Record<string, any> | any[], RT extends ResponseType = 'json', M extends Method = Method> extends Omit<RouteRequestOptions<RT, false, Q, B>, 'json' | 'body'> {
62
+ json: B;
63
+ method?: M;
64
+ }
65
+ interface RequestOptionsBody<Q = any, RT extends ResponseType = 'json', M extends Method = Method> extends Omit<RouteRequestOptions<RT, false, Q>, 'json' | 'body'> {
66
+ body: string;
67
+ method?: M;
68
+ }
69
+ type PutRequestOptions<Q = any, B = any, RT extends ResponseType = 'json'> = RequestOptionsJSON<Q, B, RT, 'PUT'> | RequestOptionsBody<Q, RT, 'PUT'>;
70
+ type PostRequestOptions<Q = any, B = any, RT extends ResponseType = 'json'> = RequestOptionsJSON<Q, B, RT, 'POST'> | RequestOptionsBody<Q, RT, 'POST'>;
71
+ type PatchRequestOptions<Q = any, B = any, RT extends ResponseType = 'json'> = RequestOptionsJSON<Q, B, RT, 'PATCH'> | RequestOptionsBody<Q, RT, 'PATCH'>;
72
+ type DeleteRequestOptions<Q = any, RT extends ResponseType = 'json'> = RouteRequestOptions<RT, false, Q>;
73
+ interface MethodRequestOptions<Q = any, B = any, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> {
74
+ get: GetRequestOptions<Q, RT, ReturnUrl>;
75
+ post: PostRequestOptions<Q, B, RT>;
76
+ put: PutRequestOptions<Q, B, RT>;
77
+ patch: PatchRequestOptions<Q, RT>;
78
+ delete: DeleteRequestOptions<Q, RT>;
79
+ }
80
+ type RequestOptionsByMethod<M extends RequestMethod, Q = any, B = any, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> = M extends keyof MethodRequestOptions ? MethodRequestOptions<Q, B, RT, ReturnUrl>[M] : never;
81
+ type ApiRouteParams = Record<string, string>;
82
+ interface LunkwillData {
83
+ status?: string;
84
+ delay_ms?: number;
85
+ }
86
+ type RouteResp<N extends RouteName, M extends RequestMethod> = N extends keyof Routes ? M extends keyof Routes[N] ? 'response' extends keyof Routes[N][M] ? Routes[N][M]['response'] : never : never : never;
87
+ type RouteQuery<N extends RouteName, M extends RequestMethod> = N extends keyof Routes ? M extends keyof Routes[N] ? 'query' extends keyof Routes[N][M] ? Routes[N][M]['query'] : any : never : never;
88
+ type RouteBody<N extends RouteName, M extends RequestMethod> = N extends keyof Routes ? M extends keyof Routes[N] ? 'body' extends keyof Routes[N][M] ? Routes[N][M]['body'] : any : never : never;
89
+ type ToReturn<T = unknown, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> = ReturnUrl extends true ? string : RT extends 'blob' ? Blob : T;
90
+ type HasRequiredKeys<T> = {
91
+ [P in keyof T]-?: object extends Pick<T, P> ? never : P;
92
+ }[keyof T] extends never ? false : true;
93
+ interface RouteMethods<N extends RouteName> {
94
+ url: HasRequiredKeys<RouteQuery<N, 'get'>> extends true ? (options: Pick<RequestOptionsByMethod<'get', RouteQuery<N, 'get'>>, 'query'>) => Promise<string> : (options?: Pick<RequestOptionsByMethod<'get', RouteQuery<N, 'get'>>, 'query'>) => Promise<string>;
95
+ get: HasRequiredKeys<RouteQuery<N, 'get'>> extends true ? <T = RouteResp<N, 'get'>, RT extends ResponseType = 'json', B extends boolean = false>(options: RequestOptionsByMethod<'get', RouteQuery<N, 'get'>, any, RT, B>) => Promise<ToReturn<T, RT, B>> : <T = RouteResp<N, 'get'>, B extends boolean = false, RT extends ResponseType = 'json'>(options?: RequestOptionsByMethod<'get', RouteQuery<N, 'get'>, any, RT, B>) => Promise<ToReturn<T, RT, B>>;
96
+ post: <T = RouteResp<N, 'post'>, RT extends ResponseType = 'json'>(options: RequestOptionsByMethod<'post', RouteQuery<N, 'post'>, RouteBody<N, 'post'>, RT>) => Promise<ToReturn<T, RT>>;
97
+ put: <T = RouteResp<N, 'put'>, RT extends ResponseType = 'json'>(options: RequestOptionsByMethod<'put', RouteQuery<N, 'put'>, RouteBody<N, 'put'>, RT>) => Promise<ToReturn<T, RT>>;
98
+ patch: <T = RouteResp<N, 'patch'>, RT extends ResponseType = 'json'>(options: RequestOptionsByMethod<'patch', RouteQuery<N, 'patch'>, RouteBody<N, 'patch'>, RT>) => Promise<ToReturn<T, RT>>;
99
+ delete: HasRequiredKeys<RouteQuery<N, 'delete'>> extends true ? <T = RouteResp<N, 'delete'>>(options: RequestOptionsByMethod<'delete', RouteQuery<N, 'delete'>>) => Promise<ToReturn<T>> : <T = RouteResp<N, 'delete'>>(options?: RequestOptionsByMethod<'delete', RouteQuery<N, 'delete'>>) => Promise<ToReturn<T>>;
100
+ }
101
+ type MethodAvailable<N extends RouteName, M extends RequestMethod> = M extends 'url' ? RouteMethods<N>['url'] : M extends keyof Routes[N] ? RouteMethods<N>[M] : never;
102
+ type RouteResults<N extends RouteName> = {
103
+ [M in keyof RouteMethods<any>]: MethodAvailable<N, M>;
104
+ };
105
+ type KeysWithMethods<Methods extends RequestMethod[]> = {
106
+ [K in keyof Routes]: Methods extends (keyof Routes[K])[] ? K : never;
107
+ }[keyof Routes];
108
+ type PathKeys = any;
109
+ type KeysWithPaths<P extends PathKeys> = {
110
+ [K in keyof Routes]: P extends Array<keyof Routes[K]['pathObj']> ? K : never;
111
+ }[keyof Routes];
112
+ type KeysWithMethodAndPath<M extends RequestMethod[], P extends PathKeys> = {
113
+ [K in keyof Routes]: K extends KeysWithMethods<M> ? K extends KeysWithPaths<P> ? K : never : never;
114
+ }[keyof Routes];
115
+
116
+ declare class AbortError extends Error {
117
+ constructor(message?: string);
118
+ }
6
119
 
7
120
  interface NgwLayerIdentifyError {
8
121
  error: 'Not implemented';
@@ -476,30 +589,12 @@ interface Permission {
476
589
  permission: string;
477
590
  propagate: boolean;
478
591
  }
479
- 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';
480
592
  interface ResourceHierarchy {
481
593
  id: number;
482
594
  parent: {
483
595
  id: any;
484
596
  };
485
597
  }
486
- interface Resource {
487
- cls: ResourceCls;
488
- id: number;
489
- parent: {
490
- id: number;
491
- };
492
- owner_user: {
493
- id: number;
494
- };
495
- permissions: Permission[];
496
- keyname?: string | null;
497
- display_name: string;
498
- description?: string | null;
499
- children: boolean;
500
- interfaces: any[];
501
- scopes: string[];
502
- }
503
598
  interface BookmarkProperties {
504
599
  name: string;
505
600
  place: string;
@@ -515,16 +610,6 @@ interface NgwTimeFormat {
515
610
  second: number;
516
611
  }
517
612
  type NgwDateTimeFormat = NgwDateFormat & NgwTimeFormat;
518
- interface WebmapResource {
519
- extent_left: number;
520
- extent_right: number;
521
- extent_bottom: number;
522
- extent_top: number;
523
- extent_constrained: boolean;
524
- draw_order_enabled: boolean;
525
- bookmark_resource: ResourceHierarchy;
526
- root_item: TreeGroup;
527
- }
528
613
  interface BasemapResource {
529
614
  url: string;
530
615
  /**
@@ -532,16 +617,6 @@ interface BasemapResource {
532
617
  */
533
618
  qms: string;
534
619
  }
535
- interface BasemapWebmapItem {
536
- resource_id: number;
537
- display_name: string;
538
- position?: number;
539
- enabled?: boolean;
540
- opacity?: number;
541
- }
542
- interface BasemapWebmap {
543
- basemaps: BasemapWebmapItem[];
544
- }
545
620
  interface LookupTableResource {
546
621
  items: Record<string, string>;
547
622
  }
@@ -557,16 +632,7 @@ interface FeatureLayerField {
557
632
  label_field: boolean;
558
633
  typemod?: unknown;
559
634
  }
560
- interface FeatureResource {
561
- fields: FeatureLayerField[];
562
- }
563
635
  type GeometryType = 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'POINTZ' | 'LINESTRINGZ' | 'POLYGONZ' | 'MULTIPOINTZ' | 'MULTILINESTRINGZ' | 'MULTIPOLYGONZ';
564
- interface VectorLayer {
565
- srs: {
566
- id: number;
567
- };
568
- geometry_type: GeometryType;
569
- }
570
636
  interface FileBucket {
571
637
  files: NgwFile[];
572
638
  tstamp?: any;
@@ -639,27 +705,6 @@ interface NgwFile {
639
705
  interface Resmeta {
640
706
  items: Record<string, any>;
641
707
  }
642
- interface ResourceItemMain {
643
- resource: Resource;
644
- resmeta: Resmeta;
645
- }
646
- interface ResourceItem extends ResourceItemMain {
647
- [cls: string]: any;
648
- webmap?: WebmapResource;
649
- feature_layer?: FeatureResource;
650
- vector_layer?: VectorLayer;
651
- basemap_layer?: BasemapResource;
652
- basemap_webmap?: BasemapWebmap;
653
- lookup_table?: LookupTableResource;
654
- file_bucket?: FileBucket;
655
- wmsserver_service?: WmsServerService;
656
- wmsclient_layer?: WmsClientLayer;
657
- wmsclient_connection?: WmsClientConnection;
658
- }
659
- interface VectorLayerResourceItem extends ResourceItemMain {
660
- vector_layer: VectorLayer;
661
- feature_layer: FeatureResource;
662
- }
663
708
 
664
709
  type ResourceStoreItemProperties = {
665
710
  [name: string]: any;
@@ -694,19 +739,11 @@ interface SrsItem {
694
739
  id: number;
695
740
  wkt: string;
696
741
  }
697
- interface Icon {
698
- format: string;
699
- data: string;
700
- }
701
- interface RenderLegendSymbol {
702
- display_name: string;
703
- icon: Icon;
704
- }
705
742
  interface FeatureLayerCount {
706
743
  total_count: number;
707
744
  }
708
745
  type ResourceIdKeynameDef = string | number;
709
- type ResourceDefinition = ResourceIdKeynameDef | DeepPartial<Resource>;
746
+ type ResourceDefinition = ResourceIdKeynameDef | DeepPartial<ResourceRead>;
710
747
  interface FileUploadResp {
711
748
  upload_meta: FileMeta[];
712
749
  }
@@ -741,10 +778,10 @@ interface RequestItemsResponseMap {
741
778
  interface GetRequestItemsResponseMap extends RequestItemKeys {
742
779
  'pyramid.route': PyramidRoute;
743
780
  'pyramid.settings': PyramidSettings;
744
- 'resource.item': ResourceItem;
745
- 'resource.search': ResourceItem[];
781
+ 'resource.item': CompositeRead;
782
+ 'resource.search': CompositeRead[];
746
783
  'resource.child': any;
747
- 'resource.collection': ResourceItem[];
784
+ 'resource.collection': CompositeRead[];
748
785
  'file_upload.upload': FileUploadResp;
749
786
  'layer.extent': NgwExtent;
750
787
  'feature_layer.feature.item': FeatureItem;
@@ -755,7 +792,7 @@ interface GetRequestItemsResponseMap extends RequestItemKeys {
755
792
  'feature_layer.feature.count': FeatureLayerCount;
756
793
  'pyramid.company_logo': string;
757
794
  'spatial_ref_sys.collection': SrsItem[];
758
- 'render.legend_symbols': RenderLegendSymbol[];
795
+ 'render.legend_symbols': LegendSymbol[];
759
796
  }
760
797
  interface IdOnly {
761
798
  id: number;
@@ -778,16 +815,52 @@ interface PutRequestItemsResponseMap extends RequestItemKeys {
778
815
  interface DeleteRequestItemsResponseMap extends RequestItemKeys {
779
816
  'feature_layer.feature.item': any;
780
817
  }
818
+ /**
819
+ * User credentials for authorization.
820
+ */
781
821
  interface Credentials {
822
+ /**
823
+ * The login username for the user.
824
+ */
782
825
  login: string;
826
+ /**
827
+ * The password for the user.
828
+ */
783
829
  password: string;
784
830
  }
785
831
  type RequestTransformFunction = (url: string, options: RequestOptions) => [url: string, options: RequestOptions];
786
832
  interface NgwConnectorOptions {
833
+ /**
834
+ * The base URL of the NextGIS Web (NGW) server.
835
+ * Example: "https://demo.nextgis.com"
836
+ */
787
837
  baseUrl?: string;
838
+ /**
839
+ * The API route path to use for requests.
840
+ * If not specified, the default route "/api/component/pyramid/route" will be used.
841
+ */
788
842
  route?: string;
843
+ /**
844
+ * User credentials for authorization in NGW.
845
+ * These credentials will be used for authentication in NGW requests.
846
+ */
789
847
  auth?: Credentials;
848
+ /**
849
+ * Indicates whether to include credentials such as cookies, authentication headers,
850
+ * or TLS client certificates in cross-site Access-Control requests.
851
+ * Setting this property ensures that cookies from another domain are used in the requests.
852
+ * Note that setting this property has no effect on same-origin requests.
853
+ */
854
+ withCredentials?: boolean;
855
+ /**
856
+ * A function to transform the request before sending it.
857
+ * This function can be used to modify the URL, headers, or other options.
858
+ */
790
859
  requestTransform?: RequestTransformFunction;
860
+ /**
861
+ * Identifier for caching requests.
862
+ * This can be used to segregate cached data for different connectors.
863
+ */
791
864
  cacheId?: string;
792
865
  }
793
866
  interface RequestHeaders {
@@ -803,19 +876,64 @@ interface BaseRequestOptions {
803
876
  cache?: boolean;
804
877
  signal?: AbortSignal;
805
878
  }
879
+ /**
880
+ * Options for configuring requests to NGW.
881
+ */
806
882
  interface RequestOptions<M extends RequestMethods = RequestMethods, K extends keyof RequestItemsParamsMap = keyof RequestItemsParamsMap> extends BaseRequestOptions {
883
+ /**
884
+ * Data to be sent as the request body.
885
+ * Typically used with POST, PUT, or PATCH requests.
886
+ */
807
887
  data?: any;
888
+ /**
889
+ * File to be sent in the request.
890
+ */
808
891
  file?: File;
892
+ /**
893
+ * HTTP method to be used for the request.
894
+ * Example: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'
895
+ */
809
896
  method?: M;
897
+ /**
898
+ * HTTP headers to be included in the request.
899
+ */
810
900
  headers?: RequestHeaders;
901
+ /**
902
+ * Indicates whether to include credentials such as cookies, authentication headers,
903
+ * or TLS client certificates in cross-site Access-Control requests.
904
+ */
811
905
  withCredentials?: boolean;
906
+ /**
907
+ * The type of data that the server will respond with.
908
+ * Can be either 'json' or 'blob'.
909
+ */
812
910
  responseType?: 'json' | 'blob';
911
+ /**
912
+ * Whether to cache the request.
913
+ * When set to true, the response will be stored in the cache.
914
+ */
813
915
  cache?: boolean;
916
+ /**
917
+ * Signal object that allows you to communicate with a DOM request (such as fetch) and abort it if desired via an AbortController.
918
+ */
814
919
  signal?: AbortSignal;
920
+ /**
921
+ * Parameters to be included in the request URL.
922
+ */
815
923
  params?: RequestItemsParams<K>;
924
+ /**
925
+ * A function to be called to monitor the progress of the request.
926
+ * @param percentComplete - The percentage of the request that has been completed.
927
+ * @param event - The progress event.
928
+ */
816
929
  onProgress?: (percentComplete: number, event: ProgressEvent) => void;
930
+ /**
931
+ * Name to use for caching the request.
932
+ */
817
933
  cacheName?: string;
818
- /** Use to override default cache props */
934
+ /**
935
+ * Properties to override default cache behavior.
936
+ */
819
937
  cacheProps?: Record<string, unknown>;
820
938
  }
821
939
  type RequestItemAdditionalParams = {
@@ -843,60 +961,6 @@ interface GetChildrenOfOptions extends Pick<RequestOptions, 'cache'> {
843
961
  recursive?: boolean;
844
962
  }
845
963
 
846
- declare class ResourcesControl {
847
- cache: Cache<Promise<ResourceItem | undefined>, {
848
- id?: number | string;
849
- }>;
850
- connector: NgwConnector;
851
- constructor({ connector, cacheId, }: {
852
- connector: NgwConnector;
853
- cacheId?: string;
854
- });
855
- /**
856
- * Receive resource from NGW by id, keyname or search-object parameter.
857
- * @param resource - Resource id, keyname or search-object
858
- *
859
- * @remarks
860
- * Fetching resource would be cached to speed up next call
861
- */
862
- getOne(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
863
- getOneOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem>;
864
- /**
865
- * A fast way to retrieve resource ID for any resource definition.
866
- * @param resource - Any available resource definition
867
- *
868
- * @remarks
869
- * There are situations when exactly the resource id is needed
870
- * (for example, to compose the correct request to the api)
871
- * then this method will come in handy to facilitate the extraction of the identifier
872
- * if the resource is specified through a keyname or other parameters.
873
- */
874
- getId(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number | undefined>;
875
- /**
876
- * A fast way to retrieve resource ID for any resource definition.
877
- * @param resource - Any available resource definition
878
- *
879
- * @remarks
880
- * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
881
- * To not make one more checks if the resource is definitely exists
882
- */
883
- getIdOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number>;
884
- getMany(resource: DeepPartial<Resource>, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem[]>;
885
- getParent(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
886
- getChildrenOf(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): Promise<ResourceItem[]>;
887
- update(resource: ResourceDefinition, data: DeepPartial<ResourceItem>): Promise<ResourceItem | undefined>;
888
- /**
889
- * Fast way to delete resource from NGW and clean cache.
890
- * @param resource - Resource definition
891
- */
892
- delete(resource: ResourceDefinition): Promise<void>;
893
- private _getChildrenOf;
894
- private _cleanResourceItemCache;
895
- private _fetchResourceById;
896
- private _fetchResourceBy;
897
- private _resourceCacheFilter;
898
- }
899
-
900
964
  /**
901
965
  * Thrown when...
902
966
  */
@@ -912,6 +976,33 @@ declare class NgwError extends Error {
912
976
  constructor(er?: Partial<NgwError>);
913
977
  }
914
978
 
979
+ /**
980
+ * Thrown when ...
981
+ */
982
+ declare class InsufficientPermissionsError extends NgwError {
983
+ name: string;
984
+ exception: NgwExceptions;
985
+ constructor(obj: InsufficientPermissionsError);
986
+ }
987
+
988
+ /**
989
+ * Thrown when...
990
+ */
991
+ declare class NetworkError extends Error {
992
+ name: string;
993
+ constructor(url: string);
994
+ }
995
+
996
+ /**
997
+ * Thrown when ...
998
+ */
999
+ declare class NetworksResponseError extends NgwError {
1000
+ message: string;
1001
+ title: string;
1002
+ detail: string;
1003
+ constructor(obj?: Partial<NetworksResponseError>);
1004
+ }
1005
+
915
1006
  /**
916
1007
  * Thrown when ...
917
1008
  */
@@ -921,22 +1012,51 @@ declare class ResourceNotFoundError extends NgwError {
921
1012
  constructor(obj?: ResourceNotFoundError);
922
1013
  }
923
1014
 
1015
+ declare function isError(error: unknown): error is Error;
1016
+
1017
+ declare function extractError(error: unknown): NetworksResponseError | {
1018
+ title: any;
1019
+ message: any;
1020
+ detail: any;
1021
+ data: any;
1022
+ } | {
1023
+ title: string;
1024
+ message: string;
1025
+ detail?: undefined;
1026
+ data?: undefined;
1027
+ } | undefined;
1028
+
1029
+ type errors_AbortError = AbortError;
1030
+ declare const errors_AbortError: typeof AbortError;
1031
+ type errors_InsufficientPermissionsError = InsufficientPermissionsError;
1032
+ declare const errors_InsufficientPermissionsError: typeof InsufficientPermissionsError;
1033
+ type errors_NetworkError = NetworkError;
1034
+ declare const errors_NetworkError: typeof NetworkError;
1035
+ type errors_NetworksResponseError = NetworksResponseError;
1036
+ declare const errors_NetworksResponseError: typeof NetworksResponseError;
1037
+ type errors_NgwError = NgwError;
1038
+ declare const errors_NgwError: typeof NgwError;
1039
+ type errors_ResourceNotFoundError = ResourceNotFoundError;
1040
+ declare const errors_ResourceNotFoundError: typeof ResourceNotFoundError;
1041
+ declare const errors_extractError: typeof extractError;
1042
+ declare const errors_isError: typeof isError;
1043
+ declare namespace errors {
1044
+ export { errors_AbortError as AbortError, errors_InsufficientPermissionsError as InsufficientPermissionsError, errors_NetworkError as NetworkError, errors_NetworksResponseError as NetworksResponseError, errors_NgwError as NgwError, errors_ResourceNotFoundError as ResourceNotFoundError, errors_extractError as extractError, errors_isError as isError };
1045
+ }
1046
+
924
1047
  declare class NgwConnector {
925
1048
  options: NgwConnectorOptions;
926
- static errors: {
927
- NgwError: typeof NgwError;
928
- ResourceNotFoundError: typeof ResourceNotFoundError;
929
- };
1049
+ static errors: typeof errors;
930
1050
  id: number;
931
1051
  emitter: EventEmitter<[never]>;
932
1052
  user?: UserInfo;
933
- resources: ResourcesControl;
934
1053
  cache: Cache;
1054
+ withCredentials?: boolean;
1055
+ private client;
935
1056
  private routeStr;
936
1057
  private activeRequests;
937
1058
  private requestTransform?;
938
1059
  constructor(options: NgwConnectorOptions);
939
- static create(options: NgwConnectorOptions): NgwConnector;
940
1060
  /**
941
1061
  * Clear the cache.
942
1062
  */
@@ -955,7 +1075,7 @@ declare class NgwConnector {
955
1075
  * Can be used to check connection.
956
1076
  * @example
957
1077
  * ```javascript
958
- * const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
1078
+ * const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
959
1079
  * connector.connect()
960
1080
  * .then(() => console.log('Ok'))
961
1081
  * .catch((er) => console.log('Connection problem', er));
@@ -975,13 +1095,89 @@ declare class NgwConnector {
975
1095
  /**
976
1096
  * Obtaining the required Headers for authentication of requests in the NGW.
977
1097
  */
978
- getAuthorizationHeaders(credentials?: Credentials): RequestHeaders | undefined;
1098
+ getAuthorizationHeaders(credentials?: Credentials): RequestHeaders;
979
1099
  makeClientId(credentials?: Credentials): string | undefined;
980
1100
  /** Stop all api requests */
981
1101
  abort(): void;
982
1102
  getActiveApiRequests(): {
983
1103
  [x: number]: AbortController;
984
1104
  };
1105
+ route<N extends RouteName>(name: N, ...rest: RouteParameters[N]): RouteResults<N>;
1106
+ /**
1107
+ * Send request to NGW.
1108
+ * @param url - URL address to NGW
1109
+ * @param params - Query params
1110
+ * @param options - Request options
1111
+ */
1112
+ makeQuery<R = unknown>(url: string, params?: Params | null, options?: RequestOptions): Promise<R>;
1113
+ protected _loadData<R = unknown>(url: string, options: RequestOptions): Promise<R>;
1114
+ private _login;
1115
+ private _cleanActiveRequest;
1116
+ private _handleHttpError;
1117
+ }
1118
+
1119
+ declare class ResourcesControl {
1120
+ cache: Cache<Promise<CompositeRead | undefined>, {
1121
+ id?: number | string;
1122
+ }>;
1123
+ connector: NgwConnectorExtended;
1124
+ constructor({ connector, cacheId, }: {
1125
+ connector: NgwConnectorExtended;
1126
+ cacheId?: string;
1127
+ });
1128
+ /**
1129
+ * Receive resource from NGW by id, keyname or search-object parameter.
1130
+ * @param resource - Resource id, keyname or search-object
1131
+ *
1132
+ * @remarks
1133
+ * Fetching resource would be cached to speed up next call
1134
+ */
1135
+ getOne(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<CompositeRead | undefined>;
1136
+ getOneOrFail(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<CompositeRead>;
1137
+ /**
1138
+ * A fast way to retrieve resource ID for any resource definition.
1139
+ * @param resource - Any available resource definition
1140
+ *
1141
+ * @remarks
1142
+ * There are situations when exactly the resource id is needed
1143
+ * (for example, to compose the correct request to the api)
1144
+ * then this method will come in handy to facilitate the extraction of the identifier
1145
+ * if the resource is specified through a keyname or other parameters.
1146
+ */
1147
+ getId(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<number | undefined>;
1148
+ /**
1149
+ * A fast way to retrieve resource ID for any resource definition.
1150
+ * @param resource - Any available resource definition
1151
+ *
1152
+ * @remarks
1153
+ * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
1154
+ * To not make one more checks if the resource is definitely exists
1155
+ */
1156
+ getIdOrFail(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<number>;
1157
+ getMany(resource: DeepPartial<ResourceRead>, requestOptions?: GetRequestOptions): Promise<CompositeRead[]>;
1158
+ getParent(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<CompositeRead | undefined>;
1159
+ getChildrenOf(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): Promise<CompositeRead[]>;
1160
+ update(resource: ResourceDefinition, data: DeepPartial<CompositeRead>): Promise<CompositeRead | undefined>;
1161
+ /**
1162
+ * Fast way to delete resource from NGW and clean cache.
1163
+ * @param resource - Resource definition
1164
+ */
1165
+ delete(resource: ResourceDefinition): Promise<void>;
1166
+ private _getChildrenOf;
1167
+ private _cleanResourceItemCache;
1168
+ private _fetchResourceById;
1169
+ private _fetchResourceBy;
1170
+ private _resourceCacheFilter;
1171
+ }
1172
+
1173
+ declare class NgwConnectorExtended extends NgwConnector {
1174
+ resources: ResourcesControl;
1175
+ constructor(options: NgwConnectorOptions);
1176
+ static create(options: NgwConnectorOptions): NgwConnectorExtended;
1177
+ /**
1178
+ * Clear the cache.
1179
+ */
1180
+ clearCache(): void;
985
1181
  /**
986
1182
  * Send request to NGW api router.
987
1183
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -1054,64 +1250,63 @@ declare class NgwConnector {
1054
1250
  * @param params - Request item params or query params
1055
1251
  */
1056
1252
  delete<K extends keyof RequestItemsParamsMap>(name: K, options?: RequestOptions<'DELETE', K> | undefined | null, params?: RequestItemsParams<K>): Promise<DeleteRequestItemsResponseMap[K]>;
1057
- /**
1058
- * Send request to NGW.
1059
- * @param url - URL address to NGW
1060
- * @param params - Query params
1061
- * @param options - Request options
1062
- */
1063
- makeQuery<R = unknown>(url: string, params?: Params | null, options?: RequestOptions): Promise<R>;
1064
1253
  /**
1065
1254
  * {@link ResourcesControl.getOne}
1066
1255
  */
1067
- getResource(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
1256
+ getResource(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<CompositeRead | undefined>;
1068
1257
  /**
1069
1258
  * {@link ResourcesControl.getOneOrFail}
1070
1259
  */
1071
- getResourceOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem>;
1260
+ getResourceOrFail(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<CompositeRead>;
1072
1261
  /**
1073
1262
  * @deprecated - use {@link getResource}
1074
1263
  */
1075
- getResourceBy(resource: DeepPartial<Resource>): Promise<ResourceItem | undefined>;
1264
+ getResourceBy(resource: DeepPartial<ResourceRead>): Promise<CompositeRead | undefined>;
1076
1265
  /**
1077
1266
  * @deprecated - use {@link getResource}
1078
1267
  */
1079
- getResourceByKeyname(keyname: string): Promise<ResourceItem | undefined>;
1268
+ getResourceByKeyname(keyname: string): Promise<CompositeRead | undefined>;
1080
1269
  /**
1081
1270
  * @deprecated - use {@link getResource}
1082
1271
  */
1083
- getResourceById(id: number): Promise<ResourceItem | undefined>;
1272
+ getResourceById(id: number): Promise<CompositeRead | undefined>;
1084
1273
  /**
1085
1274
  * {@link ResourcesControl.getId}
1086
1275
  */
1087
- getResourceId(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number | undefined>;
1276
+ getResourceId(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<number | undefined>;
1088
1277
  /**
1089
1278
  * {@link ResourcesControl.getIdOrFail}
1090
1279
  */
1091
- getResourceIdOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number>;
1280
+ getResourceIdOrFail(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<number>;
1092
1281
  /**
1093
1282
  * {@link ResourcesControl.getMany}
1094
1283
  */
1095
- getResourcesBy(resource: DeepPartial<Resource>, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem[]>;
1284
+ getResourcesBy(resource: DeepPartial<ResourceRead>, requestOptions?: GetRequestOptions): Promise<CompositeRead[]>;
1096
1285
  /**
1097
1286
  * {@link ResourcesControl.getParent}
1098
1287
  */
1099
- getResourceParent(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
1288
+ getResourceParent(resource: ResourceDefinition, requestOptions?: GetRequestOptions): Promise<CompositeRead | undefined>;
1100
1289
  /**
1101
1290
  * {@link ResourcesControl.getChildrenOf}
1102
1291
  */
1103
- getResourceChildren(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): Promise<ResourceItem[]>;
1292
+ getResourceChildren(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): Promise<CompositeRead[]>;
1104
1293
  /**
1105
1294
  * {@link ResourcesControl.update}
1106
1295
  */
1107
- updateResource(resource: ResourceIdKeynameDef, data: DeepPartial<ResourceItem>): Promise<ResourceItem | undefined>;
1296
+ updateResource(resource: ResourceIdKeynameDef, data: DeepPartial<CompositeRead>): Promise<CompositeRead | undefined>;
1108
1297
  /**
1109
1298
  * {@link ResourcesControl.delete}
1110
1299
  */
1111
1300
  deleteResource(resource: ResourceIdKeynameDef): Promise<void>;
1112
- private _login;
1113
- private _cleanActiveRequest;
1114
- private _handleHttpError;
1115
1301
  }
1116
1302
 
1117
- export { type BaseRequestOptions, type BasemapResource, type BasemapWebmap, type BasemapWebmapItem, type BookmarkProperties, type CreatedResource, type Credentials, type DeleteRequestItemsResponseMap, 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 IdOnly, type LayerFeature, type LoadingQueue, type LookupTableResource, type NgwConnectorOptions, type NgwDateFormat, type NgwDateTimeFormat, type NgwExceptions, type NgwExtent, type NgwFile, type NgwLayerIdentifyError, type NgwTimeFormat, type Params, type PatchRequestItemsResponseMap, type Permission, type PostRequestItemsResponseMap, type PutRequestItemsResponseMap, type PyramidRoute, type PyramidSettings, type PyramidSettingsPyramid, type PyramidSettingsPyramidCompanyLogo, type RenderLegendSymbol, type RequestHeaders, type RequestItemAdditionalParams, type RequestItemKeys, type RequestItemsParams, type RequestItemsParamsMap, type RequestItemsResponseMap, type RequestMethods, type RequestOptions, 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 Router, type SrsItem, type TreeGroup, type TreeItem, type TreeLayer, type UserInfo, type VectorFieldDatatype, type VectorLayer, type VectorLayerResourceItem, type WebmapResource, type WmsClientConnection, type WmsClientLayer, type WmsServerService, type WmsServerServiceLayer, NgwConnector as default };
1303
+ /**
1304
+ * Represents a legend for a specific layer.
1305
+ */
1306
+ interface LayerLegend {
1307
+ layerId: string;
1308
+ legend: LegendSymbol[];
1309
+ setSymbolRender?: (symbolIndex: number, status: boolean) => void;
1310
+ }
1311
+
1312
+ export { type ApiRouteParams, type BaseRequestOptions, type BasemapResource, 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 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 ResourceDefinition, type ResourceHierarchy, type ResourceIdKeynameDef, 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 WmsClientConnection, type WmsClientLayer, type WmsServerService, type WmsServerServiceLayer, NgwConnectorExtended as default };