@nextgis/geocoder 1.17.0 → 1.18.3

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
@@ -6,25 +6,77 @@
6
6
  */
7
7
 
8
8
  import CancelablePromise from '@nextgis/cancelable-promise';
9
+ import type { FeatureItem } from '@nextgis/ngw-connector';
10
+ import type { FetchNgwItemsOptions } from '@nextgis/ngw-kit';
9
11
  import { GeoJsonObject } from 'geojson';
10
12
  import { LngLatBoundsArray } from '@nextgis/utils';
11
13
  import NgwConnector from '@nextgis/ngw-connector';
12
- import { ResourceStoreItem } from '@nextgis/ngw-connector';
14
+ import type { NgwConnectorOptions } from '@nextgis/ngw-connector';
15
+ import type { ResourceItem } from '@nextgis/ngw-connector';
13
16
 
17
+ /**
18
+ * Represents the base class for a geocoder.
19
+ * This abstract class provides the basic methods that every geocoder should implement.
20
+ *
21
+ * @template O - The type of options that can be passed to the geocoder.
22
+ */
14
23
  declare abstract class BaseGeocoder<O extends Record<string, any> = Record<string, any>> {
15
24
  constructor(options?: O);
25
+ /**
26
+ * Search method to retrieve geocoding results.
27
+ *
28
+ * @abstract
29
+ * @param {string} query - The search string to geocode.
30
+ * @yields {AsyncGenerator<SearchItem>} - An async generator that yields search results.
31
+ */
16
32
  abstract search(query: string): AsyncGenerator<SearchItem>;
33
+ /**
34
+ * Method to retrieve detailed result for a specific search item.
35
+ *
36
+ * @abstract
37
+ * @param {SearchItem} item - The search item to get detailed result for.
38
+ * @returns {CancelablePromise<any>} - A promise that resolves to the detailed result.
39
+ */
17
40
  abstract result(item: SearchItem): CancelablePromise<any>;
41
+ /**
42
+ * Optional method to abort any ongoing geocoding requests.
43
+ *
44
+ * @abstract
45
+ */
18
46
  abstract abort?(): void;
19
47
  }
20
48
 
49
+ /**
50
+ * Abstract base class representing a search provider.
51
+ * It builds upon the BaseGeocoder functionalities with provider-specific properties.
52
+ * @template O - Options type which extends BaseProviderOptions.
53
+ */
21
54
  export declare abstract class BaseProvider<O extends BaseProviderOptions = BaseProviderOptions> extends BaseGeocoder<O> {
55
+ /**
56
+ * URL endpoint for the search service.
57
+ * This is where queries will be sent to obtain search results.
58
+ */
22
59
  searchUrl?: string;
60
+ /**
61
+ * Label to represent the provider.
62
+ * Useful for user interfaces to display the source of search results.
63
+ */
23
64
  label?: string;
24
65
  }
25
66
 
67
+ /**
68
+ * Options for initializing a basic search provider.
69
+ */
26
70
  export declare interface BaseProviderOptions {
71
+ /**
72
+ * URL endpoint for the search service.
73
+ * This is where queries will be sent to obtain search results.
74
+ */
27
75
  searchUrl?: string;
76
+ /**
77
+ * Label to represent the provider.
78
+ * This could be used for user interfaces to display the source of search results.
79
+ */
28
80
  label?: string;
29
81
  }
30
82
 
@@ -38,31 +90,54 @@ export declare class Geocoder extends BaseGeocoder<GeocoderOptions> {
38
90
  result(item: SearchItem): CancelablePromise<any>;
39
91
  }
40
92
 
93
+ /**
94
+ * Defines the options for creating a Geocoder instance.
95
+ */
41
96
  export declare interface GeocoderOptions {
97
+ /**
98
+ * An array of providers to be used for geocoding.
99
+ */
42
100
  providers: BaseProvider[];
43
101
  }
44
102
 
45
103
  export declare class NgwProvider extends BaseProvider<NgwProviderOptions> {
104
+ static limit: number;
46
105
  caseInsensitive: boolean;
47
- searchUrl: string;
48
106
  searchResources: SearchResource[];
49
107
  private connector;
50
- private requests;
108
+ private _abortControllers;
51
109
  constructor(options: NgwProviderOptions);
52
110
  abort(): void;
53
- search(like: string): AsyncGenerator<NgwSearchItem, void, unknown>;
111
+ search(query: string): AsyncGenerator<NgwSearchItem, void, unknown>;
54
112
  result(item: NgwSearchItem): CancelablePromise<ResultItem>;
55
- _items(entries: ResourceStoreItem[]): NgwSearchItem[];
113
+ private _makeSignal;
114
+ private _items;
56
115
  }
57
116
 
117
+ /**
118
+ * Options required to initialize an NGW provider.
119
+ */
58
120
  declare interface NgwProviderOptions extends BaseProviderOptions {
121
+ /** Connector instance for NGW. If not provided, will be created internally */
59
122
  connector?: NgwConnector;
123
+ /** List of NGW resources to search within */
60
124
  searchResources: SearchResource[];
125
+ /** Options for the internal NgwConnector (if one needs to be created) */
126
+ connectorOptions?: NgwConnectorOptions;
61
127
  }
62
128
 
129
+ /**
130
+ * Extends the basic search item with NGW-specific properties.
131
+ */
63
132
  declare interface NgwSearchItem extends SearchItem {
133
+ /** ID of the NGW resource */
64
134
  resourceId: number;
135
+ /** ID of the feature in the NGW resource */
65
136
  featureId: number;
137
+ /** The specific feature item from NGW */
138
+ item: FeatureItem;
139
+ /** The NGW resource item */
140
+ resourceItem: ResourceItem;
66
141
  }
67
142
 
68
143
  export declare class NominatimProvider extends BaseProvider {
@@ -74,26 +149,74 @@ export declare class NominatimProvider extends BaseProvider {
74
149
  result(model: SearchItem): CancelablePromise<ResultItem>;
75
150
  }
76
151
 
152
+ /**
153
+ * Defines the structure for a rendered search item.
154
+ */
155
+ declare interface RenderSearchItem {
156
+ /** The specific feature item */
157
+ item: FeatureItem;
158
+ /** The NGW resource item */
159
+ resourceItem: ResourceItem;
160
+ }
161
+
77
162
  export declare interface ResultItem {
163
+ /**
164
+ * Display text of the result item.
165
+ */
78
166
  text: string;
167
+ /**
168
+ * Bounding box of the result item in [west, south, east, north] format.
169
+ */
79
170
  extent: LngLatBoundsArray;
171
+ /**
172
+ * Optional GeoJSON geometry associated with this result item.
173
+ */
80
174
  geom?: GeoJsonObject;
81
175
  }
82
176
 
83
177
  export declare interface SearchItem {
178
+ /**
179
+ * A dynamic property bucket for the `SearchItem`.
180
+ */
84
181
  [prop: string]: any;
182
+ /**
183
+ * An optional unique identifier for the search result.
184
+ */
85
185
  _id?: number | string;
186
+ /**
187
+ * Display text of the search result.
188
+ */
86
189
  text: string;
190
+ /**
191
+ * The original query string that resulted in this search result.
192
+ */
87
193
  query: string;
194
+ /**
195
+ * An optional bounding box of the search result in [west, south, east, north] format.
196
+ */
88
197
  extent?: LngLatBoundsArray;
198
+ /**
199
+ * The provider that sourced this search result.
200
+ */
89
201
  provider?: BaseProvider;
202
+ /**
203
+ * Optional GeoJSON geometry associated with this search result.
204
+ */
90
205
  geom?: GeoJsonObject;
206
+ /**
207
+ * An optional function that can be called to retrieve detailed result for this search item.
208
+ */
91
209
  result?: () => CancelablePromise<ResultItem>;
92
210
  }
93
211
 
94
- declare interface SearchResource {
95
- id: number;
96
- limit?: number;
212
+ /**
213
+ * Options for searching within a NGW resource.
214
+ */
215
+ declare interface SearchResource extends FetchNgwItemsOptions {
216
+ /** The search method used ('ilike' is case-insensitive) */
217
+ searchMethod?: 'ilike' | 'like';
218
+ /** Custom rendering function for search results */
219
+ renderSearch?: (item: RenderSearchItem) => string | HTMLElement;
97
220
  }
98
221
 
99
222
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextgis/geocoder",
3
- "version": "1.17.0",
3
+ "version": "1.18.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "lib/geocoder.esm-bundler.js",
@@ -8,8 +8,9 @@
8
8
  "jsdelivr": "lib/geocoder.global.prod.js",
9
9
  "types": "lib/index.d.ts",
10
10
  "dependencies": {
11
- "@nextgis/cancelable-promise": "^1.17.0",
12
- "@nextgis/ngw-connector": "^1.17.0",
11
+ "@nextgis/cancelable-promise": "^1.18.3",
12
+ "@nextgis/ngw-connector": "^1.18.3",
13
+ "@nextgis/ngw-kit": "^1.18.3",
13
14
  "@nextgis/utils": "^1.17.0",
14
15
  "@types/events": "^3.0.0",
15
16
  "@types/geojson": "^7946.0.8",
@@ -52,5 +53,5 @@
52
53
  "bugs": {
53
54
  "url": "https://github.com/nextgis/nextgis_frontend/issues"
54
55
  },
55
- "gitHead": "c3162aae53c381cd6a581a2a67173fb1bf6de87e"
56
+ "gitHead": "2e9e5b8f6125faab208899bb4581392721af04cd"
56
57
  }