import { Store } from 'store-api/api'; /** * Provides search functionality (use `search-api.SearchService` OSGi service name). */ interface SearchService { /** * Returns `true` if the service knows a store with the given ID. */ hasStore(storeId: string): boolean; /** * Searches items on one or more data sources using the given query. * * @param query the search query * @param options options to customize the search * @returns An object that represents the state of the search. */ search(query: string, options?: SearchOptions): Search; } /** * Describes the supported options in a call to `SearchService.search(...)`. */ interface SearchOptions { /** * Optional signal to cancel the search. * When the signal's `abort` event fires, all individual search operations are cancelled * and promises returned by a search will *reject* with an `AbortError`. * * See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal. */ signal?: AbortSignal; /** * IDs of stores to search. If not provided, all available stores are searched. */ stores?: string[]; /** * Optional context parameter that is passed through the search-api. * This value can be used to indicate the origin of the search (e.g. a UI widget or bundle). * * See also {@link QueryEvent.context} and {@link SelectedEvent.context}. */ context?: string; /** * An optional number of items requested from each store. * Note that the implementation may return fewer results if the * stores do not provide that many items in a single query. * * By default, only a single query is made to every store. * * The default value is `15`. */ count?: number; /** * Whether to request the number of total results from the queries stores. * * This is true by default for backwards compatibility reasons. * Set this to `false` to skip requesting the total result count. * * See also {@link ResultSet.total}. */ queryTotal?: boolean; /** * An optional array of map action IDs. * The associated map actions are triggered when an item is selected (see {@link ResultItem.select}). * This option corresponds to the `actionIds` parameter of the `map-actions.ActionService.trigger()` method. * * Defaults to the action IDs `"highlight"`, `"zoomto"` and `"openpopup"` defined by the `map-actions` bundle. */ actions?: string[]; /** * An optional object with action options to use when an item is selected (see {@link ResultItem.select}). * This option corresponds to the `options` parameter of the `map-actions.ActionService.trigger()` method. */ actionOptions?: Record; } /** The state of a search. */ type SearchStatus = "running" | "done" | "cancelled" | "error"; /** * The result of a `search()` call. Result items arrive asynchronously. * * Search objects are kept simple by design. * They are always suitable to be placed into a Vue instance (e.g. in `data`). */ interface Search { /** * Current state of this search. */ readonly state: SearchStatus; /** * Result map (id -> group of results). * As individual sub searches complete, results will become * available in the `group` objects. */ readonly groups: { readonly [id: string]: ResultGroup; }; } /** * A result group within a search. */ interface ResultGroup { /** * Group label for display purposes (e.g. layer name). */ readonly label: string; /** * Current state of this result group. */ readonly state: SearchStatus; /** * Search results for this group. * When the search is cancelled, this promise will *reject* * with an `AbortError` (see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). */ readonly result: Promise; /** * Priority of this result group in relation to other groups. * A lower value indicates a higher priority. */ readonly priority: number; } interface ResultSet { /** Result items, up to the requested amount. */ readonly items: ResultItem[]; /** * Total number of available results. * * This is present if the `queryTotal` option is set to `true` (the default). * This is always undefined if `queryTotal` is set to `false`. */ readonly total: number | undefined; /** * Selects multiple items at once. * The items must belong to this result set (from `this.items`). * * When using this method, make sure that the configured map actions * can handle multiple items at once. * * See also {@link ResultItem.select} for more details. */ select(items: ResultItem[]): ResultSelectionHandle; } /** * A single result item, for example describing a feature. */ interface ResultItem { /** * Unique id of this item within its group. */ readonly id: string | number; /** * Item label for display purposes. */ readonly label: string; /** * Invoke actions associated with the item. * For example, zooming to a feature or opening a popup. * * This function returns a handle object with a `remove()` function * that will clear side effects made by the selection, if applicable (e.g. highlights). * * Note that selections may also be removed automatically (e.g. when a new selection is made). * * To select multiple items at once, see {@link ResultGroup.select}. */ select(): ResultSelectionHandle; } /** * Cleanup handle returned when a result item has been selected. */ interface ResultSelectionHandle { /** * A cleanup function to clear side effects made by the selection, if applicable (e.g. highlights). */ remove(): void; } /** * An event emitted via the Event Service using the topic name `search-api/QUERY`. */ interface QueryEvent { /** * The original search query entered by the user. */ readonly query: string; /** * Context parameter that was specified when the search was started. * * May indicate the UI widget or bundle where the search was originally triggered. * * See also {@link SearchOptions.context}. */ readonly context: string | undefined; } /** * An event emitted via the Event Service using the topic name `search-api/SELECTED`. */ interface SelectedEvent { /** * The original search query entered by the user. */ readonly query: string; /** * Context parameter that was specified when the search was started. * * May indicate the UI widget or bundle where the search was originally triggered. * * See also {@link SearchOptions.context}. */ readonly context: string | undefined; /** * The source of the selected item. * Currently all sources are stores, but different source types may be added in the future. * Use the `type` field for disambiguation. */ readonly source: ItemSource; /** * The selected item (for single selection). * * Mutually exclusive with {@link items}. */ readonly item?: Record; /** * The selected items (for multi selection). * * Mutually exclusive with {@link item}. */ readonly items?: Record[]; } /** Describes the item source for a selection event. */ interface ItemSource { /** * The type of this source. Currently always 'store', but more types (with different properties) * may be added later. */ readonly type: "store"; /** Store instance that returned the item. */ readonly store: Store; /** Service properties of the store (if any). */ readonly storeProperties: Readonly>; } export type { ItemSource, QueryEvent, ResultGroup, ResultItem, ResultSelectionHandle, ResultSet, Search, SearchOptions, SearchService, SearchStatus, SelectedEvent };