@nextgis/ngw-connector 3.0.0-alpha.4 → 3.0.0-alpha.6

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,98 @@
1
+ import { Routes } from '@nextgisweb/pyramid/type/route';
1
2
  import { EventEmitter } from 'events';
2
3
  import Cache from '@nextgis/cache';
3
4
  import { FeatureProperties, DeepPartial } from '@nextgis/utils';
4
5
  import { GeoJsonObject, Geometry } from 'geojson';
5
6
 
7
+ declare class LunkwillParam {
8
+ static VALUES: (string | null)[];
9
+ private value;
10
+ constructor();
11
+ update(value: string | null, cond?: boolean): void;
12
+ suggest(cond?: boolean): void;
13
+ require(cond?: boolean): void;
14
+ toHeaders(headers: Record<string, string>): void;
15
+ }
16
+
17
+ type RouteParameters = {
18
+ [K in keyof Routes]: Routes[K]['pathArr'] | [Routes[K]['pathObj']];
19
+ };
20
+ type RouteName = keyof Routes;
21
+ type RequestMethod = keyof RouteMethods<RouteName>;
22
+ type Method = RequestMethod | Uppercase<RequestMethod>;
23
+ type ResponseType = 'blob' | 'json';
24
+ interface RequestOptions$1<RT extends ResponseType = 'json', ReturnUrl extends boolean = false, Q = any, B = string | null | boolean | Record<string, any> | any[]> extends Omit<RequestInit, 'cache'> {
25
+ headers?: Record<string, string>;
26
+ cache?: boolean;
27
+ query?: Q;
28
+ json?: B;
29
+ /** Has lower priority than the json */
30
+ body?: string;
31
+ /**
32
+ * The type of data that the server will respond with.
33
+ * Can be either 'json' or 'blob'.
34
+ */
35
+ responseType?: RT;
36
+ /**
37
+ * @deprecated use {@link RequestInit.credential}
38
+ * Indicates whether to include credentials such as cookies, authentication headers,
39
+ * or TLS client certificates in cross-site Access-Control requests.
40
+ */
41
+ withCredentials?: boolean;
42
+ /**
43
+ * Name to use for caching the request.
44
+ */
45
+ cacheName?: string;
46
+ /**
47
+ * Properties to override default cache behavior.
48
+ */
49
+ cacheProps?: Record<string, unknown>;
50
+ lunkwill?: LunkwillParam;
51
+ lunkwillReturnUrl?: ReturnUrl;
52
+ }
53
+ interface GetRequestOptions<Q = any, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> extends Omit<RequestOptions$1<RT, ReturnUrl, Q>, 'json' | 'body'> {
54
+ method?: 'GET';
55
+ }
56
+ interface RequestOptionsJSON<Q = any, B = string | null | boolean | Record<string, any> | any[], RT extends ResponseType = 'json', M extends Method = Method> extends Omit<RequestOptions$1<RT, false, Q, B>, 'json' | 'body'> {
57
+ json: B;
58
+ method?: M;
59
+ }
60
+ interface RequestOptionsBody<Q = any, RT extends ResponseType = 'json', M extends Method = Method> extends Omit<RequestOptions$1<RT, false, Q>, 'json' | 'body'> {
61
+ body: string;
62
+ method?: M;
63
+ }
64
+ type PutRequestOptions<Q = any, B = any, RT extends ResponseType = 'json'> = RequestOptionsJSON<Q, B, RT, 'PUT'> | RequestOptionsBody<Q, RT, 'PUT'>;
65
+ type PostRequestOptions<Q = any, B = any, RT extends ResponseType = 'json'> = RequestOptionsJSON<Q, B, RT, 'POST'> | RequestOptionsBody<Q, RT, 'POST'>;
66
+ type PatchRequestOptions<Q = any, B = any, RT extends ResponseType = 'json'> = RequestOptionsJSON<Q, B, RT, 'PATCH'> | RequestOptionsBody<Q, RT, 'PATCH'>;
67
+ type DeleteRequestOptions<Q = any, RT extends ResponseType = 'json'> = RequestOptions$1<RT, false, Q>;
68
+ interface RouteRequestOptions<Q = any, B = any, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> {
69
+ get: GetRequestOptions<Q, RT, ReturnUrl>;
70
+ post: PostRequestOptions<Q, B, RT>;
71
+ put: PutRequestOptions<Q, B, RT>;
72
+ patch: PatchRequestOptions<Q, RT>;
73
+ delete: DeleteRequestOptions<Q, RT>;
74
+ }
75
+ type RequestOptionsByMethod<M extends RequestMethod, Q = any, B = any, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> = M extends keyof RouteRequestOptions ? RouteRequestOptions<Q, B, RT, ReturnUrl>[M] : never;
76
+ 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;
77
+ 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;
78
+ 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;
79
+ type ToReturn<T = unknown, RT extends ResponseType = 'json', ReturnUrl extends boolean = false> = ReturnUrl extends true ? string : RT extends 'blob' ? Blob : T;
80
+ type HasRequiredKeys<T> = {
81
+ [P in keyof T]-?: object extends Pick<T, P> ? never : P;
82
+ }[keyof T] extends never ? false : true;
83
+ interface RouteMethods<N extends RouteName> {
84
+ 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>;
85
+ 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>>;
86
+ post: <T = RouteResp<N, 'post'>, RT extends ResponseType = 'json'>(options: RequestOptionsByMethod<'post', RouteQuery<N, 'post'>, RouteBody<N, 'post'>, RT>) => Promise<ToReturn<T, RT>>;
87
+ put: <T = RouteResp<N, 'put'>, RT extends ResponseType = 'json'>(options: RequestOptionsByMethod<'put', RouteQuery<N, 'put'>, RouteBody<N, 'put'>, RT>) => Promise<ToReturn<T, RT>>;
88
+ patch: <T = RouteResp<N, 'patch'>, RT extends ResponseType = 'json'>(options: RequestOptionsByMethod<'patch', RouteQuery<N, 'patch'>, RouteBody<N, 'patch'>, RT>) => Promise<ToReturn<T, RT>>;
89
+ 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>>;
90
+ }
91
+ type MethodAvailable<N extends RouteName, M extends RequestMethod> = M extends 'url' ? RouteMethods<N>['url'] : M extends keyof Routes[N] ? RouteMethods<N>[M] : never;
92
+ type RouteResults<N extends RouteName> = {
93
+ [M in keyof RouteMethods<any>]: MethodAvailable<N, M>;
94
+ };
95
+
6
96
  interface NgwLayerIdentifyError {
7
97
  error: 'Not implemented';
8
98
  }
@@ -958,60 +1048,6 @@ interface GetChildrenOfOptions extends Pick<RequestOptions, 'cache'> {
958
1048
  recursive?: boolean;
959
1049
  }
960
1050
 
961
- declare class ResourcesControl {
962
- cache: Cache<Promise<ResourceItem | undefined>, {
963
- id?: number | string;
964
- }>;
965
- connector: NgwConnector;
966
- constructor({ connector, cacheId, }: {
967
- connector: NgwConnector;
968
- cacheId?: string;
969
- });
970
- /**
971
- * Receive resource from NGW by id, keyname or search-object parameter.
972
- * @param resource - Resource id, keyname or search-object
973
- *
974
- * @remarks
975
- * Fetching resource would be cached to speed up next call
976
- */
977
- getOne(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
978
- getOneOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem>;
979
- /**
980
- * A fast way to retrieve resource ID for any resource definition.
981
- * @param resource - Any available resource definition
982
- *
983
- * @remarks
984
- * There are situations when exactly the resource id is needed
985
- * (for example, to compose the correct request to the api)
986
- * then this method will come in handy to facilitate the extraction of the identifier
987
- * if the resource is specified through a keyname or other parameters.
988
- */
989
- getId(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number | undefined>;
990
- /**
991
- * A fast way to retrieve resource ID for any resource definition.
992
- * @param resource - Any available resource definition
993
- *
994
- * @remarks
995
- * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
996
- * To not make one more checks if the resource is definitely exists
997
- */
998
- getIdOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number>;
999
- getMany(resource: DeepPartial<Resource>, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem[]>;
1000
- getParent(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
1001
- getChildrenOf(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): Promise<ResourceItem[]>;
1002
- update(resource: ResourceDefinition, data: DeepPartial<ResourceItem>): Promise<ResourceItem | undefined>;
1003
- /**
1004
- * Fast way to delete resource from NGW and clean cache.
1005
- * @param resource - Resource definition
1006
- */
1007
- delete(resource: ResourceDefinition): Promise<void>;
1008
- private _getChildrenOf;
1009
- private _cleanResourceItemCache;
1010
- private _fetchResourceById;
1011
- private _fetchResourceBy;
1012
- private _resourceCacheFilter;
1013
- }
1014
-
1015
1051
  /**
1016
1052
  * Thrown when...
1017
1053
  */
@@ -1045,7 +1081,6 @@ declare class NgwConnector {
1045
1081
  id: number;
1046
1082
  emitter: EventEmitter<[never]>;
1047
1083
  user?: UserInfo;
1048
- resources: ResourcesControl;
1049
1084
  cache: Cache;
1050
1085
  withCredentials?: boolean;
1051
1086
  private client;
@@ -1072,7 +1107,7 @@ declare class NgwConnector {
1072
1107
  * Can be used to check connection.
1073
1108
  * @example
1074
1109
  * ```javascript
1075
- * const connector = new NgwConnector({baseUrl: 'https://demo.nextgis.com'});
1110
+ * const connector = new NgwConnector({ baseUrl: 'https://demo.nextgis.com' });
1076
1111
  * connector.connect()
1077
1112
  * .then(() => console.log('Ok'))
1078
1113
  * .catch((er) => console.log('Connection problem', er));
@@ -1092,13 +1127,88 @@ declare class NgwConnector {
1092
1127
  /**
1093
1128
  * Obtaining the required Headers for authentication of requests in the NGW.
1094
1129
  */
1095
- getAuthorizationHeaders(credentials?: Credentials): RequestHeaders | undefined;
1130
+ getAuthorizationHeaders(credentials?: Credentials): RequestHeaders;
1096
1131
  makeClientId(credentials?: Credentials): string | undefined;
1097
1132
  /** Stop all api requests */
1098
1133
  abort(): void;
1099
1134
  getActiveApiRequests(): {
1100
1135
  [x: number]: AbortController;
1101
1136
  };
1137
+ route<N extends RouteName>(name: N, ...rest: RouteParameters[N]): RouteResults<N>;
1138
+ /**
1139
+ * Send request to NGW.
1140
+ * @param url - URL address to NGW
1141
+ * @param params - Query params
1142
+ * @param options - Request options
1143
+ */
1144
+ makeQuery<R = unknown>(url: string, params?: Params | null, options?: RequestOptions): Promise<R>;
1145
+ protected _loadData<R = unknown>(url: string, options: RequestOptions): Promise<R>;
1146
+ private _login;
1147
+ private _cleanActiveRequest;
1148
+ private _handleHttpError;
1149
+ }
1150
+
1151
+ declare class ResourcesControl {
1152
+ cache: Cache<Promise<ResourceItem | undefined>, {
1153
+ id?: number | string;
1154
+ }>;
1155
+ connector: NgwConnectorExtended;
1156
+ constructor({ connector, cacheId, }: {
1157
+ connector: NgwConnectorExtended;
1158
+ cacheId?: string;
1159
+ });
1160
+ /**
1161
+ * Receive resource from NGW by id, keyname or search-object parameter.
1162
+ * @param resource - Resource id, keyname or search-object
1163
+ *
1164
+ * @remarks
1165
+ * Fetching resource would be cached to speed up next call
1166
+ */
1167
+ getOne(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
1168
+ getOneOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem>;
1169
+ /**
1170
+ * A fast way to retrieve resource ID for any resource definition.
1171
+ * @param resource - Any available resource definition
1172
+ *
1173
+ * @remarks
1174
+ * There are situations when exactly the resource id is needed
1175
+ * (for example, to compose the correct request to the api)
1176
+ * then this method will come in handy to facilitate the extraction of the identifier
1177
+ * if the resource is specified through a keyname or other parameters.
1178
+ */
1179
+ getId(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number | undefined>;
1180
+ /**
1181
+ * A fast way to retrieve resource ID for any resource definition.
1182
+ * @param resource - Any available resource definition
1183
+ *
1184
+ * @remarks
1185
+ * Similar with {@link NgwConnector.getResourceId | getResourceId} but rise error if resource is not exist.
1186
+ * To not make one more checks if the resource is definitely exists
1187
+ */
1188
+ getIdOrFail(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<number>;
1189
+ getMany(resource: DeepPartial<Resource>, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem[]>;
1190
+ getParent(resource: ResourceDefinition, requestOptions?: RequestOptions<'GET'>): Promise<ResourceItem | undefined>;
1191
+ getChildrenOf(resource: ResourceDefinition, requestOptions?: GetChildrenOfOptions): Promise<ResourceItem[]>;
1192
+ update(resource: ResourceDefinition, data: DeepPartial<ResourceItem>): Promise<ResourceItem | undefined>;
1193
+ /**
1194
+ * Fast way to delete resource from NGW and clean cache.
1195
+ * @param resource - Resource definition
1196
+ */
1197
+ delete(resource: ResourceDefinition): Promise<void>;
1198
+ private _getChildrenOf;
1199
+ private _cleanResourceItemCache;
1200
+ private _fetchResourceById;
1201
+ private _fetchResourceBy;
1202
+ private _resourceCacheFilter;
1203
+ }
1204
+
1205
+ declare class NgwConnectorExtended extends NgwConnector {
1206
+ resources: ResourcesControl;
1207
+ constructor(options: NgwConnectorOptions);
1208
+ /**
1209
+ * Clear the cache.
1210
+ */
1211
+ clearCache(): void;
1102
1212
  /**
1103
1213
  * Send request to NGW api router.
1104
1214
  * @param name - NGW route name from {@link https://docs.nextgis.com/docs_ngweb_dev/doc/developer/resource.html#routes | routes}
@@ -1171,13 +1281,6 @@ declare class NgwConnector {
1171
1281
  * @param params - Request item params or query params
1172
1282
  */
1173
1283
  delete<K extends keyof RequestItemsParamsMap>(name: K, options?: RequestOptions<'DELETE', K> | undefined | null, params?: RequestItemsParams<K>): Promise<DeleteRequestItemsResponseMap[K]>;
1174
- /**
1175
- * Send request to NGW.
1176
- * @param url - URL address to NGW
1177
- * @param params - Query params
1178
- * @param options - Request options
1179
- */
1180
- makeQuery<R = unknown>(url: string, params?: Params | null, options?: RequestOptions): Promise<R>;
1181
1284
  /**
1182
1285
  * {@link ResourcesControl.getOne}
1183
1286
  */
@@ -1226,9 +1329,6 @@ declare class NgwConnector {
1226
1329
  * {@link ResourcesControl.delete}
1227
1330
  */
1228
1331
  deleteResource(resource: ResourceIdKeynameDef): Promise<void>;
1229
- private _login;
1230
- private _cleanActiveRequest;
1231
- private _handleHttpError;
1232
1332
  }
1233
1333
 
1234
- 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 LayerLegend, type LegendItem, type LegendItemSymbol, 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 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 };
1334
+ 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 LayerLegend, type LegendItem, type LegendItemSymbol, 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 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, NgwConnectorExtended as default };