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

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 CHANGED
@@ -46,6 +46,38 @@ We recommend linking to a specific version number `/ngw-connector@[version]`
46
46
  npm install @nextgis/ngw-connector
47
47
  ```
48
48
 
49
+ ## TypeScript Support
50
+
51
+ If you plan to use this library in a TypeScript project, it's recommended to install TypeScript declaration files for NextGIS Web by using the `@nextgis/ngw-types-loader` tool.
52
+
53
+ ### Installing NGW Types
54
+
55
+ Run the following command to download the latest TypeScript declaration files:
56
+
57
+ ```bash
58
+ npx @nextgis/ngw-types-loader
59
+ ```
60
+
61
+ This will download the declaration file from the default NextGIS Web instance (`https://demo.nextgis.com`) and update your `tsconfig.json` to include it.
62
+
63
+ If you are using a custom NextGIS Web deployment, you can specify the URL:
64
+
65
+ ```bash
66
+ npx @nextgis/ngw-types-loader https://your-custom-ngw-url.com
67
+ ```
68
+
69
+ After running the tool, ensure that your `tsconfig.json` includes the downloaded file:
70
+
71
+ ```json
72
+ {
73
+ "include": [
74
+ "./nextgisweb.d.ts"
75
+ ]
76
+ }
77
+ ```
78
+
79
+ For more details, refer to the [NGW Types Loader](https://www.npmjs.com/package/@nextgis/ngw-types-loader).
80
+
49
81
  ## Usage
50
82
 
51
83
  ```javascript
@@ -56,22 +88,25 @@ const ngwConnector = new NgwConnector({
56
88
  // auth: {login, password}
57
89
  });
58
90
 
59
- ngwConnector.get('resource.item', null, { id: 485 }).then((data) => {
60
- console.log(data);
61
- });
91
+ ngwConnector
92
+ .route('resource.item', { id: 485 })
93
+ .get()
94
+ .then((data) => {
95
+ console.log(data);
96
+ });
62
97
 
63
- ngwConnector.post('resource.collection', { data: [RESOURCE JSON] });
64
- ngwConnector.patch(
65
- 'feature_layer.feature.collection',
66
- { data: [ITEMS JSON] },
67
- {
68
- id,
98
+ ngwConnector.route('resource.collection').patch({ json: RESOURCE });
99
+ ngwConnector.route('feature_layer.feature.collection', { id }).patch({
100
+ json: ITEMS,
101
+ query: {
69
102
  srs: 4326,
70
103
  geom_format: 'geojson',
71
- }
72
- );
73
- ngwConnector.put('feature_layer.feature.item', { data: [ITEM JSON] }, { id, fid })
74
- ngwConnector.delete('feature_layer.feature.item', null, { id, fid })
104
+ },
105
+ });
106
+ ngwConnector
107
+ .route('feature_layer.feature.item', { id, fid })
108
+ .put({ json: ITEM });
109
+ ngwConnector.route('feature_layer.feature.item', { id, fid }).delete();
75
110
 
76
111
  // Shortcuts methods to find resources
77
112
  ngwConnector.getResource(2011); // by id
package/lib/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Routes } from '@nextgisweb/pyramid/type/route';
2
- import { EventEmitter } from 'events';
3
2
  import Cache from '@nextgis/cache';
3
+ import { EventEmitter } from 'events';
4
4
  import { FeatureProperties, DeepPartial } from '@nextgis/utils';
5
- import { GeoJsonObject, Geometry } from 'geojson';
6
5
  import { LegendSymbol } from '@nextgisweb/render/type/api';
7
6
  import { ResourceRead, CompositeRead } from '@nextgisweb/resource/type/api';
7
+ import { GeoJsonObject, Geometry } from 'geojson';
8
8
 
9
9
  declare class LunkwillParam {
10
10
  static VALUES: (string | null)[];
@@ -589,12 +589,32 @@ interface Permission {
589
589
  permission: string;
590
590
  propagate: boolean;
591
591
  }
592
+ /** @deprecated use ResourceCls from '@nextgisweb/resource/type/api' instead */
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';
592
594
  interface ResourceHierarchy {
593
595
  id: number;
594
596
  parent: {
595
597
  id: any;
596
598
  };
597
599
  }
600
+ /** @deprecated use ResourceRead from '@nextgisweb/resource/type/api' instead */
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
+ }
598
618
  interface BookmarkProperties {
599
619
  name: string;
600
620
  place: string;
@@ -610,6 +630,17 @@ interface NgwTimeFormat {
610
630
  second: number;
611
631
  }
612
632
  type NgwDateTimeFormat = NgwDateFormat & NgwTimeFormat;
633
+ /** @deprecated use WebMapRead from '@nextgisweb/resource/type/api' instead */
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
+ }
613
644
  interface BasemapResource {
614
645
  url: string;
615
646
  /**
@@ -617,6 +648,18 @@ interface BasemapResource {
617
648
  */
618
649
  qms: string;
619
650
  }
651
+ /** @deprecated use BasemapWebMapItemRead from '@nextgisweb/resource/type/api' instead */
652
+ interface BasemapWebmapItem {
653
+ resource_id: number;
654
+ display_name: string;
655
+ position?: number;
656
+ enabled?: boolean;
657
+ opacity?: number;
658
+ }
659
+ /** @deprecated use BasemapWebMapRead from '@nextgisweb/resource/type/api' instead */
660
+ interface BasemapWebmap {
661
+ basemaps: BasemapWebmapItem[];
662
+ }
620
663
  interface LookupTableResource {
621
664
  items: Record<string, string>;
622
665
  }
@@ -632,7 +675,18 @@ interface FeatureLayerField {
632
675
  label_field: boolean;
633
676
  typemod?: unknown;
634
677
  }
678
+ /** @deprecated use FeatureLayerRead from '@nextgisweb/resource/type/api' instead */
679
+ interface FeatureResource {
680
+ fields: FeatureLayerField[];
681
+ }
635
682
  type GeometryType = 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'POINTZ' | 'LINESTRINGZ' | 'POLYGONZ' | 'MULTIPOINTZ' | 'MULTILINESTRINGZ' | 'MULTIPOLYGONZ';
683
+ /** @deprecated use VectorLayerRead from '@nextgisweb/resource/type/api' instead */
684
+ interface VectorLayer {
685
+ srs: {
686
+ id: number;
687
+ };
688
+ geometry_type: GeometryType;
689
+ }
636
690
  interface FileBucket {
637
691
  files: NgwFile[];
638
692
  tstamp?: any;
@@ -705,6 +759,28 @@ interface NgwFile {
705
759
  interface Resmeta {
706
760
  items: Record<string, any>;
707
761
  }
762
+ interface ResourceItemMain {
763
+ resource: Resource;
764
+ resmeta: Resmeta;
765
+ }
766
+ /** @deprecated use CompositeRead from '@nextgisweb/resource/type/api' instead */
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
+ }
708
784
 
709
785
  type ResourceStoreItemProperties = {
710
786
  [name: string]: any;
@@ -874,7 +950,7 @@ type RequestMethods = 'POST' | 'GET' | 'PATCH' | 'DELETE' | 'PUT';
874
950
  type NgwExceptions = 'nextgisweb.resource.exception.ResourceNotFound' | 'nextgisweb.core.exception.InsufficientPermissions';
875
951
  interface BaseRequestOptions {
876
952
  cache?: boolean;
877
- signal?: AbortSignal;
953
+ signal?: AbortSignal | null;
878
954
  }
879
955
  /**
880
956
  * Options for configuring requests to NGW.
@@ -916,7 +992,7 @@ interface RequestOptions<M extends RequestMethods = RequestMethods, K extends ke
916
992
  /**
917
993
  * Signal object that allows you to communicate with a DOM request (such as fetch) and abort it if desired via an AbortController.
918
994
  */
919
- signal?: AbortSignal;
995
+ signal?: AbortSignal | null;
920
996
  /**
921
997
  * Parameters to be included in the request URL.
922
998
  */
@@ -976,6 +1052,28 @@ declare class NgwError extends Error {
976
1052
  constructor(er?: Partial<NgwError>);
977
1053
  }
978
1054
 
1055
+ /**
1056
+ * Thrown when ...
1057
+ */
1058
+ declare class NetworksResponseError extends NgwError {
1059
+ message: string;
1060
+ title: string;
1061
+ detail: string;
1062
+ constructor(obj?: Partial<NetworksResponseError>);
1063
+ }
1064
+
1065
+ declare function extractError(error: unknown): NetworksResponseError | {
1066
+ title: any;
1067
+ message: any;
1068
+ detail: any;
1069
+ data: any;
1070
+ } | {
1071
+ title: string;
1072
+ message: string;
1073
+ detail?: undefined;
1074
+ data?: undefined;
1075
+ } | undefined;
1076
+
979
1077
  /**
980
1078
  * Thrown when ...
981
1079
  */
@@ -985,6 +1083,8 @@ declare class InsufficientPermissionsError extends NgwError {
985
1083
  constructor(obj: InsufficientPermissionsError);
986
1084
  }
987
1085
 
1086
+ declare function isError(error: unknown): error is Error;
1087
+
988
1088
  /**
989
1089
  * Thrown when...
990
1090
  */
@@ -993,16 +1093,6 @@ declare class NetworkError extends Error {
993
1093
  constructor(url: string);
994
1094
  }
995
1095
 
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
-
1006
1096
  /**
1007
1097
  * Thrown when ...
1008
1098
  */
@@ -1012,20 +1102,6 @@ declare class ResourceNotFoundError extends NgwError {
1012
1102
  constructor(obj?: ResourceNotFoundError);
1013
1103
  }
1014
1104
 
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
1105
  type errors_AbortError = AbortError;
1030
1106
  declare const errors_AbortError: typeof AbortError;
1031
1107
  type errors_InsufficientPermissionsError = InsufficientPermissionsError;
@@ -1081,7 +1157,7 @@ declare class NgwConnector {
1081
1157
  * .catch((er) => console.log('Connection problem', er));
1082
1158
  * ```
1083
1159
  */
1084
- connect(): Promise<PyramidRoute>;
1160
+ connect({ signal, }?: Pick<RequestOptions, 'signal'>): Promise<PyramidRoute>;
1085
1161
  /**
1086
1162
  * Quick way to change NextGIS Web user.
1087
1163
  * @param credentials - New user credentials
@@ -1309,4 +1385,4 @@ interface LayerLegend {
1309
1385
  setSymbolRender?: (symbolIndex: number, status: boolean) => void;
1310
1386
  }
1311
1387
 
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 };
1388
+ 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 };