@nextgis/geocoder 1.17.0 → 1.18.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
@@ -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,53 @@ 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> {
46
- caseInsensitive: boolean;
47
- searchUrl: string;
104
+ static limit: number;
48
105
  searchResources: SearchResource[];
49
106
  private connector;
50
- private requests;
107
+ private _abortControllers;
51
108
  constructor(options: NgwProviderOptions);
52
109
  abort(): void;
53
- search(like: string): AsyncGenerator<NgwSearchItem, void, unknown>;
110
+ search(query: string): AsyncGenerator<NgwSearchItem, void, unknown>;
54
111
  result(item: NgwSearchItem): CancelablePromise<ResultItem>;
55
- _items(entries: ResourceStoreItem[]): NgwSearchItem[];
112
+ private _makeSignal;
113
+ private _items;
56
114
  }
57
115
 
116
+ /**
117
+ * Options required to initialize an NGW provider.
118
+ */
58
119
  declare interface NgwProviderOptions extends BaseProviderOptions {
120
+ /** Connector instance for NGW. If not provided, will be created internally */
59
121
  connector?: NgwConnector;
122
+ /** List of NGW resources to search within */
60
123
  searchResources: SearchResource[];
124
+ /** Options for the internal NgwConnector (if one needs to be created) */
125
+ connectorOptions?: NgwConnectorOptions;
61
126
  }
62
127
 
128
+ /**
129
+ * Extends the basic search item with NGW-specific properties.
130
+ */
63
131
  declare interface NgwSearchItem extends SearchItem {
132
+ /** ID of the NGW resource */
64
133
  resourceId: number;
134
+ /** ID of the feature in the NGW resource */
65
135
  featureId: number;
136
+ /** The specific feature item from NGW */
137
+ item: FeatureItem;
138
+ /** The NGW resource item */
139
+ resourceItem: ResourceItem;
66
140
  }
67
141
 
68
142
  export declare class NominatimProvider extends BaseProvider {
@@ -74,26 +148,74 @@ export declare class NominatimProvider extends BaseProvider {
74
148
  result(model: SearchItem): CancelablePromise<ResultItem>;
75
149
  }
76
150
 
151
+ /**
152
+ * Defines the structure for a rendered search item.
153
+ */
154
+ declare interface RenderSearchItem {
155
+ /** The specific feature item */
156
+ item: FeatureItem;
157
+ /** The NGW resource item */
158
+ resourceItem: ResourceItem;
159
+ }
160
+
77
161
  export declare interface ResultItem {
162
+ /**
163
+ * Display text of the result item.
164
+ */
78
165
  text: string;
166
+ /**
167
+ * Bounding box of the result item in [west, south, east, north] format.
168
+ */
79
169
  extent: LngLatBoundsArray;
170
+ /**
171
+ * Optional GeoJSON geometry associated with this result item.
172
+ */
80
173
  geom?: GeoJsonObject;
81
174
  }
82
175
 
83
176
  export declare interface SearchItem {
177
+ /**
178
+ * A dynamic property bucket for the `SearchItem`.
179
+ */
84
180
  [prop: string]: any;
181
+ /**
182
+ * An optional unique identifier for the search result.
183
+ */
85
184
  _id?: number | string;
185
+ /**
186
+ * Display text of the search result.
187
+ */
86
188
  text: string;
189
+ /**
190
+ * The original query string that resulted in this search result.
191
+ */
87
192
  query: string;
193
+ /**
194
+ * An optional bounding box of the search result in [west, south, east, north] format.
195
+ */
88
196
  extent?: LngLatBoundsArray;
197
+ /**
198
+ * The provider that sourced this search result.
199
+ */
89
200
  provider?: BaseProvider;
201
+ /**
202
+ * Optional GeoJSON geometry associated with this search result.
203
+ */
90
204
  geom?: GeoJsonObject;
205
+ /**
206
+ * An optional function that can be called to retrieve detailed result for this search item.
207
+ */
91
208
  result?: () => CancelablePromise<ResultItem>;
92
209
  }
93
210
 
94
- declare interface SearchResource {
95
- id: number;
96
- limit?: number;
211
+ /**
212
+ * Options for searching within a NGW resource.
213
+ */
214
+ declare interface SearchResource extends FetchNgwItemsOptions {
215
+ /** The search method used ('ilike' is case-insensitive) */
216
+ searchMethod?: 'ilike' | 'like';
217
+ /** Custom rendering function for search results */
218
+ renderSearch?: (item: RenderSearchItem) => string | HTMLElement;
97
219
  }
98
220
 
99
221
  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.6",
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.4",
13
+ "@nextgis/ngw-kit": "^1.18.6",
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": "0402a2fa8f938e9e9b13b5021d9b7ad3c7e7b14c"
56
57
  }