diff --git a/types/react-instantsearch/connectors/index.d.ts b/types/react-instantsearch/connectors/index.d.ts index dfec18cb0e..2cf2613ffd 100644 --- a/types/react-instantsearch/connectors/index.d.ts +++ b/types/react-instantsearch/connectors/index.d.ts @@ -1,203 +1,205 @@ -declare module 'react-instantsearch/connectors' { - import { AlgoliaError, BasicDoc, ConnectedComponentType, ISearchResults, ISearchState } from 'react-instantsearch/types' +import { AlgoliaError, BasicDoc, ConnectedComponentType, SearchResults, SearchState } from '../types'; - export function connectConfigure(...args: any[]): any - - type NESW = { northEast: { lat: number, lng: number }, southWest: { lat: number, lng: number } } - - interface IGeoSearchExposed { - defaultRefinement?: NESW - } - interface IGeoSearchProvided { - /** a function to toggle the refinement */ - refine?: (refinement: NESW) => void - /** a function to generate a URL for the corresponding search state */ - createURL?: Function - /** the records that matched the search */ - hits: THit[] - /** true if the current refinement is set with the map bounds */ - isRefinedWithMap?: boolean - /** the refinement currently applied */ - currentRefinement?: NESW - /** the position of the search */ - position?: { lat: number, lng: number } - } - /** - * The GeoSearch connector provides the logic to build a widget that will display the results on a map. - * It also provides a way to search for results based on their position. The connector provides function to manage the - * search experience (search on map interaction). - * - * https://community.algolia.com/react-instantsearch/connectors/connectGeoSearch.html - */ - export function connectGeoSearch, THit>(ctor: React.ComponentType): ConnectedComponentType, IGeoSearchExposed> - export function connectCurrentRefinements(...args: any[]): any - export function connectHierarchicalMenu(...args: any[]): any - export function connectHighlight(...args: any[]): any - - /** - * connectHits connector provides the logic to create connected components that will render the results retrieved from Algolia. - * To configure the number of hits retrieved, use HitsPerPage widget, connectHitsPerPage connector or pass the hitsPerPage prop to a Configure widget. - * Warning: you will need to use the objectID property available on every hit as a key when iterating over them. This will ensure you have the best possible UI experience especially on slow networks. - * - * https://community.algolia.com/react-instantsearch/connectors/connectHits.html - */ - export function connectHits(ctor: React.ComponentType): ConnectedComponentType - - export function connectAutoComplete(...args: any[]): any - export function connectHitsPerPage(...args: any[]): any - export function connectInfiniteHits(...args: any[]): any - - interface IMenuProvided { - items?: Array<{count: number, isRefined: boolean, label: string, value: string}>, - currentRefinement?: string, - refine?: Function, - createURL?: Function, - searchForItems?: Function, - isFromSearch?: boolean - } - interface IMenuExposed { - attribute: string - showMore?: boolean, - limit?: number, - showMoreLimit?: number, - defaultRefinement?: string, - transformItems?: Function, - searchable?: boolean, - } - /** - * connectMenu connector provides the logic to build a widget that will give the user the ability to choose a single value for a specific facet. - * - * https://community.algolia.com/react-instantsearch/connectors/connectMenu.html - */ - export function connectMenu(ctor: React.ComponentType): ConnectedComponentType - - interface INumericMenuProvided { - /** the list of ranges the NumericMenu can display. */ - items?: Array<{isRefined: boolean, label: string, value: string, noRefinement: boolean}>, - /** - * the refinement currently applied. follow the shape of a string with a pattern of '{start}:{end}' which corresponds to the current selected item. - * For instance, when the selected item is {start: 10, end: 20}, the searchState of the widget is '10:20'. When start isn’t defined, the searchState - * of the widget is ':{end}', and the same way around when end isn’t defined. However, when neither start nor end are defined, the searchState is an empty string. - */ - currentRefinement?: string, - /** a function to select a range. */ - refine?: Function, - /** a function to generate a URL for the corresponding search state */ - createURL?: Function - } - interface INumericMenuExposed { - id?: string - /** the name of the attribute in the records */ - attribute: string - /** List of options. With a text label, and upper and lower bounds. */ - items: Array<{ - label: string | JSX.Element, - start?: number, - end?: number, - }> - /** the value of the item selected by default, follow the shape of a string with a pattern of '{start}:{end}'. */ - defaultRefinement?: string - /** Function to modify the items being displayed, e.g. for filtering or sorting them. Takes an items as parameter and expects it back in return. */ - transformItems?: Function - } - /** - * connectNumericMenu connector provides the logic to build a widget that will give the user the ability to select a range value for a numeric attribute. - * Ranges are defined statically. - * - * https://community.algolia.com/react-instantsearch/connectors/connectNumericMenu.html - */ - export function connectNumericMenu(ctor: React.ComponentType): ConnectedComponentType - export function connectPagination(...args: any[]): any - export function connectPoweredBy(...args: any[]): any - export function connectRange(...args: any[]): any - - interface IRefinementListProvided { - /** a function to toggle a refinement */ - refine: Function, - /** a function to generate a URL for the corresponding search state */ - createURL: Function, - /** the refinement currently applied */ - currentRefinement: string[], - /** the list of items the RefinementList can display. */ - items: Array<{ count: number, isRefined: boolean, label: string, value: string }>, - /** a function to toggle a search inside items values */ - searchForItems: Function, - /** a boolean that says if the items props contains facet values from the global search or from the search inside items. */ - isFromSearch: boolean - } - interface IRefinementListExposed { - /** the name of the attribute in the record */ - attribute: string, - /** allow search inside values */ - searchable?: boolean - /** How to apply the refinements. Possible values: ‘or’ or ‘and’. */ - operator?: 'or' | 'and' - /** true if the component should display a button that will expand the number of items */ - showMore?: boolean - /** the minimum number of displayed items */ - limit?: number - /** the maximun number of displayed items. Only used when showMore is set to true */ - showMoreLimit?: number - /** - * the values of the items selected by default. The searchState of this widget takes the form of a list of strings, which correspond to the values of all selected refinements. However, when there are no refinements selected, the value of the searchState is an empty string. - */ - defaultRefinement: string[] - /** Function to modify the items being displayed, e.g. for filtering or sorting them. Takes an items as parameter and expects it back in return. */ - transformItems?: Function - } - - /** - * connectRefinementList connector provides the logic to build a widget that will give the user the ability to choose multiple values for a specific facet. - * - * https://community.algolia.com/react-instantsearch/connectors/connectRefinementList.html - */ - export function connectRefinementList(ctor: React.ComponentType): ConnectedComponentType - export function connectScrollTo(...args: any[]): any - export function connectBreadcrumb(...args: any[]): any - - export interface ISearchBoxProvided { - /** a function to change the current query */ - refine?: Function - /** the current query used */ - currentRefinement?: string - /** a flag that indicates if InstantSearch has detected that searches are stalled */ - isSearchStalled?: boolean - } - export interface ISearchBoxExposed { - /** Provide a default value for the query */ - defaultRefinement?: string - } - export function connectSearchBox(ctor: React.ComponentType): ConnectedComponentType - export function connectSortBy(...args: any[]): any - export function connectStats(...args: any[]): any - export function connectToggleRefinement(...args: any[]): any - - export interface IStateResultsProvided { - /** The search state of the instant search component. */ - searchState?: ISearchState, - /** - * The search results. - * In case of multiple indices: if used under , results will be those of the corresponding index - * otherwise it’ll be those of the root index - */ - searchResults?: ISearchResults, - /** In case of multiple indices you can retrieve all the results */ - allSearchResults?: ISearchResults, - /** If there is a search in progress. */ - searching?: boolean, - /** Flag that indicates if React InstantSearch has detected that searches are stalled. */ - isSearchStalled?: any, - /** If the search failed, the error will be logged here. */ - error?: AlgoliaError, - /** If there is a search in a list in progress. */ - searchingForFacetValues?: any - } - /** - * The connectStateResults connector provides a way to access the `searchState` and the `searchResults` of InstantSearch. - * For instance this connector allows you to create results/noResults or query/noQuery pages. - * - * https://community.algolia.com/react-instantsearch/connectors/connectStateResults.html - */ - export function connectStateResults, TDoc>(ctor: React.ComponentType): ConnectedComponentType> +export function connectConfigure(...args: any[]): any; +export interface NESW { + northEast: { lat: number, lng: number }; + southWest: { lat: number, lng: number }; } + +export interface GeoSearchExposed { + defaultRefinement?: NESW; +} +export interface GeoSearchProvided { + /** a function to toggle the refinement */ + refine?: (refinement: NESW) => void; + /** a function to generate a URL for the corresponding search state */ + createURL?: (...args: any[]) => any; + /** the records that matched the search */ + hits: THit[]; + /** true if the current refinement is set with the map bounds */ + isRefinedWithMap?: boolean; + /** the refinement currently applied */ + currentRefinement?: NESW; + /** the position of the search */ + position?: { lat: number, lng: number }; +} +/** + * The GeoSearch connector provides the logic to build a widget that will display the results on a map. + * It also provides a way to search for results based on their position. The connector provides function to manage the + * search experience (search on map interaction). + * + * https://community.algolia.com/react-instantsearch/connectors/connectGeoSearch.html + */ +export function connectGeoSearch, THit>(ctor: React.ComponentType): ConnectedComponentType, IGeoSearchExposed>; +export function connectCurrentRefinements(...args: any[]): any; +export function connectHierarchicalMenu(...args: any[]): any; +export function connectHighlight(...args: any[]): any; + +/** + * connectHits connector provides the logic to create connected components that will render the results retrieved from Algolia. + * To configure the number of hits retrieved, use HitsPerPage widget, connectHitsPerPage connector or pass the hitsPerPage prop to a Configure widget. + * Warning: you will need to use the objectID property available on every hit as a key when iterating over them. This will ensure you have the best possible UI experience especially on slow networks. + * + * https://community.algolia.com/react-instantsearch/connectors/connectHits.html + */ +export function connectHits(ctor: React.ComponentType): ConnectedComponentType; + +export function connectAutoComplete(...args: any[]): any; +export function connectHitsPerPage(...args: any[]): any; +export function connectInfiniteHits(...args: any[]): any; + +export interface MenuProvided { + items?: Array<{count: number, isRefined: boolean, label: string, value: string}>; + currentRefinement?: string; + refine?: (...args: any[]) => any; + createURL?: (...args: any[]) => any; + searchForItems?: (...args: any[]) => any; + isFromSearch?: boolean; +} +export interface MenuExposed { + attribute: string; + showMore?: boolean; + limit?: number; + showMoreLimit?: number; + defaultRefinement?: string; + transformItems?: (...args: any[]) => any; + searchable?: boolean; +} +/** + * connectMenu connector provides the logic to build a widget that will give the user the ability to choose a single value for a specific facet. + * + * https://community.algolia.com/react-instantsearch/connectors/connectMenu.html + */ +export function connectMenu(ctor: React.ComponentType): ConnectedComponentType; + +export interface NumericMenuProvided { + /** the list of ranges the NumericMenu can display. */ + items?: Array<{isRefined: boolean, label: string, value: string, noRefinement: boolean}>; + /** + * the refinement currently applied. follow the shape of a string with a pattern of '{start}:{end}' which corresponds to the current selected item. + * For instance, when the selected item is {start: 10, end: 20}, the searchState of the widget is '10:20'. When start isn’t defined, the searchState + * of the widget is ':{end}', and the same way around when end isn’t defined. However, when neither start nor end are defined, the searchState is an empty string. + */ + currentRefinement?: string; + /** a function to select a range. */ + refine?: (...args: any[]) => any; + /** a function to generate a URL for the corresponding search state */ + createURL?: (...args: any[]) => any; +} +export interface NumericMenuExposed { + id?: string; + /** the name of the attribute in the records */ + attribute: string; + /** List of options. With a text label, and upper and lower bounds. */ + items: Array<{ + label: string | JSX.Element; + start?: number; + end?: number; + }>; + /** the value of the item selected by default, follow the shape of a string with a pattern of '{start}:{end}'. */ + defaultRefinement?: string; + /** (...args: any[]) => any to modify the items being displayed, e.g. for filtering or sorting them. Takes an items as parameter and expects it back in return. */ + transformItems?: (...args: any[]) => any; +} +/** + * connectNumericMenu connector provides the logic to build a widget that will give the user the ability to select a range value for a numeric attribute. + * Ranges are defined statically. + * + * https://community.algolia.com/react-instantsearch/connectors/connectNumericMenu.html + */ +export function connectNumericMenu(ctor: React.ComponentType): ConnectedComponentType; +export function connectPagination(...args: any[]): any; +export function connectPoweredBy(...args: any[]): any; +export function connectRange(...args: any[]): any; + +export interface RefinementListProvided { + /** a function to toggle a refinement */ + refine: (...args: any[]) => any; + /** a function to generate a URL for the corresponding search state */ + createURL: (...args: any[]) => any; + /** the refinement currently applied */ + currentRefinement: string[]; + /** the list of items the RefinementList can display. */ + items: Array<{ count: number, isRefined: boolean, label: string, value: string }>; + /** a function to toggle a search inside items values */ + searchForItems: (...args: any[]) => any; + /** a boolean that says if the items props contains facet values from the global search or from the search inside items. */ + isFromSearch: boolean; +} +export interface RefinementListExposed { + /** the name of the attribute in the record */ + attribute: string; + /** allow search inside values */ + searchable?: boolean; + /** How to apply the refinements. Possible values: ‘or’ or ‘and’. */ + operator?: 'or' | 'and'; + /** true if the component should display a button that will expand the number of items */ + showMore?: boolean; + /** the minimum number of displayed items */ + limit?: number; + /** the maximun number of displayed items. Only used when showMore is set to true */ + showMoreLimit?: number; + /** + * the values of the items selected by default. The searchState of this widget takes the form of a list of strings, + * which correspond to the values of all selected refinements. However, when there are no refinements selected, + * the value of the searchState is an empty string. + */ + defaultRefinement: string[]; + /** (...args: any[]) => any to modify the items being displayed, e.g. for filtering or sorting them. Takes an items as parameter and expects it back in return. */ + transformItems?: (...args: any[]) => any; +} + +/** + * connectRefinementList connector provides the logic to build a widget that will give the user the ability to choose multiple values for a specific facet. + * + * https://community.algolia.com/react-instantsearch/connectors/connectRefinementList.html + */ +export function connectRefinementList(ctor: React.ComponentType): ConnectedComponentType; +export function connectScrollTo(...args: any[]): any; +export function connectBreadcrumb(...args: any[]): any; + +export interface SearchBoxProvided { + /** a function to change the current query */ + refine?: (...args: any[]) => any; + /** the current query used */ + currentRefinement?: string; + /** a flag that indicates if InstantSearch has detected that searches are stalled */ + isSearchStalled?: boolean; +} +export interface SearchBoxExposed { + /** Provide a default value for the query */ + defaultRefinement?: string; +} +export function connectSearchBox(ctor: React.ComponentType): ConnectedComponentType; +export function connectSortBy(...args: any[]): any; +export function connectStats(...args: any[]): any; +export function connectToggleRefinement(...args: any[]): any; + +export interface StateResultsProvided { + /** The search state of the instant search component. */ + searchState?: SearchState; + /** + * The search results. + * In case of multiple indices: if used under , results will be those of the corresponding index + * otherwise it’ll be those of the root index + */ + searchResults?: SearchResults; + /** In case of multiple indices you can retrieve all the results */ + allSearchResults?: SearchResults; + /** If there is a search in progress. */ + searching?: boolean; + /** Flag that indicates if React InstantSearch has detected that searches are stalled. */ + isSearchStalled?: any; + /** If the search failed, the error will be logged here. */ + error?: AlgoliaError; + /** If there is a search in a list in progress. */ + searchingForFacetValues?: any; +} +/** + * The connectStateResults connector provides a way to access the `searchState` and the `searchResults` of InstantSearch. + * For instance this connector allows you to create results/noResults or query/noQuery pages. + * + * https://community.algolia.com/react-instantsearch/connectors/connectStateResults.html + */ +export function connectStateResults, TDoc>(ctor: React.ComponentType): ConnectedComponentType>; diff --git a/types/react-instantsearch/dom/index.d.ts b/types/react-instantsearch/dom/index.d.ts index 74ae6fbada..445736f0b6 100644 --- a/types/react-instantsearch/dom/index.d.ts +++ b/types/react-instantsearch/dom/index.d.ts @@ -1,110 +1,107 @@ -declare module 'react-instantsearch/dom' { - import { Hit, BasicDoc } from 'react-instantsearch/types' +import { Hit, BasicDoc } from '../types'; - // Core - export function createConnector(...args: any[]): any +// Core +export function createConnector(...args: any[]): any; - // Widget +// Widget +/** + * Configure is a widget that lets you provide raw search parameters to the Algolia API. + * Any of the props added to this widget will be forwarded to Algolia. For more information on the different parameters that can be set, have a look at the reference. + * + * https://community.algolia.com/react-instantsearch/widgets/Configure.html + */ +export class Configure extends React.Component {} + +// DOM +export interface CommonWidgetProps { /** - * Configure is a widget that lets you provide raw search parameters to the Algolia API. - * Any of the props added to this widget will be forwarded to Algolia. For more information on the different parameters that can be set, have a look at the reference. - * - * https://community.algolia.com/react-instantsearch/widgets/Configure.html + * All static text rendered by widgets, such as “Load more”, “Show more” are translatable using the translations prop on relevant widgets. + * This prop is a mapping of keys to translation values. Translation values can be either a String or a (...args: any[]) => any, as some take parameters. + * + * https://community.algolia.com/react-instantsearch/guide/i18n.html */ - export class Configure extends React.Component{} - - // DOM - interface CommonWidgetProps { - /** - * All static text rendered by widgets, such as “Load more”, “Show more” are translatable using the translations prop on relevant widgets. - * This prop is a mapping of keys to translation values. Translation values can be either a String or a Function, as some take parameters. - * - * https://community.algolia.com/react-instantsearch/guide/i18n.html - */ - translations?: { [key: string]: string | Function } - } - - interface InstantSearchProps { - apiKey: string, - appId: string, - indexName: string, - - algoliaClient?: any, - searchClient?: any, - createURL?: Function, - searchState?: any, - refresh?: boolean, - onSearchStateChange?: Function, - onSearchParameters?: Function, - resultsState?: any | any[], - root?: { - Root: string | Function, - props: any - } - } - /** - * is the root component of all React InstantSearch implementations. It provides all the connected components (aka widgets) a means to interact with the searchState. - * - * https://community.algolia.com/react-instantsearch/widgets/%3CInstantSearch%3E.html - */ - export class InstantSearch extends React.Component {} - export class Index extends React.Component {} - export class Breadcrumb extends React.Component {} - export class ClearRefinements extends React.Component {} - export class CurrentRefinements extends React.Component {} - export class HierarchicalMenu extends React.Component {} - export class Highlight extends React.Component {} - - interface HitsProps { - hitComponent: React.ComponentType<{ hit: Hit }> - } - /** - * Displays a list of hits. - * To configure the number of hits being shown, use the HitsPerPage widget, connectHitsPerPage connector or the Configure widget. - * - * https://community.algolia.com/react-instantsearch/widgets/Hits.html - */ - export class Hits extends React.Component> {} - export class HitsPerPage extends React.Component {} - export class InfiniteHits extends React.Component {} - export class Menu extends React.Component {} - export class MenuSelect extends React.Component {} - export class NumericMenu extends React.Component {} - export class Pagination extends React.Component {} - export class Panel extends React.Component {} - export class PoweredBy extends React.Component {} - export class RangeInput extends React.Component {} - export class RangeSlider extends React.Component {} - export class RatingMenu extends React.Component {} - export class RefinementList extends React.Component {} - export class ScrollTo extends React.Component {} - - interface SearchBoxProps extends CommonWidgetProps { - focusShortcuts?: string[], - autoFocus?: boolean, - defaultRefinement?: string, - searchAsYouType?: boolean, - showLoadingIndicator?: boolean, - - submit?: JSX.Element, - reset?: JSX.Element, - loadingIndicator?: JSX.Element, - - onSubmit?: Function, - onReset?: Function, - } - /** - * The SearchBox component displays a search box that lets the user search for a specific query. - * - * https://community.algolia.com/react-instantsearch/widgets/SearchBox.html - */ - export class SearchBox extends React.Component {} - export class Snippet extends React.Component {} - export class SortBy extends React.Component {} - /** - * The Stats component displays the total number of matching hits and the time it took to get them (time spent in the Algolia server). - */ - export class Stats extends React.Component<{translations?: { [key: string]: (n: number, ms: number) => string }}> {} - export class ToggleRefinement extends React.Component {} + translations?: { [key: string]: string | (...args: any[]) => any }; } +export interface InstantSearchProps { + apiKey: string; + appId: string; + indexName: string; + + algoliaClient?: any; + searchClient?: any; + createURL?: (...args: any[]) => any; + searchState?: any; + refresh?: boolean; + onSearchStateChange?: (...args: any[]) => any; + onSearchParameters?: (...args: any[]) => any; + resultsState?: any; + root?: { + Root: string | (...args: any[]) => any; + props: any; + }; +} +/** + * is the root component of all React InstantSearch implementations. It provides all the connected components (aka widgets) a means to interact with the searchState. + * + * https://community.algolia.com/react-instantsearch/widgets/%3CInstantSearch%3E.html + */ +export class InstantSearch extends React.Component {} +export class Index extends React.Component {} +export class Breadcrumb extends React.Component {} +export class ClearRefinements extends React.Component {} +export class CurrentRefinements extends React.Component {} +export class HierarchicalMenu extends React.Component {} +export class Highlight extends React.Component {} + +export interface HitsProps { + hitComponent: React.ComponentType<{ hit: Hit }>; +} +/** + * Displays a list of hits. + * To configure the number of hits being shown, use the HitsPerPage widget, connectHitsPerPage connector or the Configure widget. + * + * https://community.algolia.com/react-instantsearch/widgets/Hits.html + */ +export class Hits extends React.Component> {} +export class HitsPerPage extends React.Component {} +export class InfiniteHits extends React.Component {} +export class Menu extends React.Component {} +export class MenuSelect extends React.Component {} +export class NumericMenu extends React.Component {} +export class Pagination extends React.Component {} +export class Panel extends React.Component {} +export class PoweredBy extends React.Component {} +export class RangeInput extends React.Component {} +export class RangeSlider extends React.Component {} +export class RatingMenu extends React.Component {} +export class RefinementList extends React.Component {} +export class ScrollTo extends React.Component {} + +export interface SearchBoxProps extends CommonWidgetProps { + focusShortcuts?: string[]; + autoFocus?: boolean; + defaultRefinement?: string; + searchAsYouType?: boolean; + showLoadingIndicator?: boolean; + + submit?: JSX.Element; + reset?: JSX.Element; + loadingIndicator?: JSX.Element; + + onSubmit?: (...args: any[]) => any; + onReset?: (...args: any[]) => any; +} +/** + * The SearchBox component displays a search box that lets the user search for a specific query. + * + * https://community.algolia.com/react-instantsearch/widgets/SearchBox.html + */ +export class SearchBox extends React.Component {} +export class Snippet extends React.Component {} +export class SortBy extends React.Component {} +/** + * The Stats component displays the total number of matching hits and the time it took to get them (time spent in the Algolia server). + */ +export class Stats extends React.Component<{translations?: { [key: string]: (n: number, ms: number) => string }}> {} +export class ToggleRefinement extends React.Component {} diff --git a/types/react-instantsearch/types/index.d.ts b/types/react-instantsearch/types/index.d.ts index 46e34f02a8..0cfa59bd50 100644 --- a/types/react-instantsearch/types/index.d.ts +++ b/types/react-instantsearch/types/index.d.ts @@ -1,272 +1,267 @@ -declare module 'react-instantsearch/types' { +export interface AlgoliaError { + stack: string; + name: string; + message: string; + debugData: any[]; + statusCode: number; +} - type AlgoliaError = { - stack: string - name: string - message: string - debugData: any[], - statusCode: number - } - +export type Omit = Pick>; - type Omit = Pick> +export type ConnectedComponentType + = React.ComponentType & TExposedProps>; - type ConnectedComponentType - = React.ComponentType & TExposedProps> +/** + * The searchState contains all widgets states. If a widget uses an attribute, + * we store it under its widget category to prevent collision. + * + * https://community.algolia.com/react-instantsearch/guide/Search_state.html + */ +export interface SearchState { + range: { + [key: string]: { + min: number; + max: number; + } + }; + configure: { + aroundLatLng: boolean; + [key: string]: any; + }; + refinementList: { + [key: string]: string[] + }; + hierarchicalMenu: { + [key: string]: string + }; + menu: { + [key: string]: string + }; + multiRange: { + [key: string]: string + }; + toggle: { + [key: string]: boolean + }; + hitsPerPage: number; + sortBy: string; + query: string; + page: number; + indices?: { + [index: string]: { + configure: { + hitsPerPage: number, + }, + } + }; +} - /** - * The searchState contains all widgets states. If a widget uses an attribute, - * we store it under its widget category to prevent collision. - * - * https://community.algolia.com/react-instantsearch/guide/Search_state.html - */ - export interface ISearchState { - range: { - [key: string]: { - min: number, - max: number - } +/** + * The most basic possible document in an Algolia index: + * a set of string-value pairs. + */ +export interface BasicDoc { [k: string]: string; } + +/** + * The shape of the searchResults object provided + * via connectors + * https://community.algolia.com/algoliasearch-helper-js/reference.html#searchresults + */ +export interface SearchResults { + query: string; + hits: Array>; + index: string; + hitsPerPage: number; + nbHits: number; + nbPages: number; + page: number; + processingTimeMS: number; + exhaustiveNbHits: true; + disjunctiveFacets: any[]; + hierarchicalFacets: any[]; + facets: any[]; + aroundLatLng?: string; + automaticRadius?: string; +} + +/** + * All the records that match the search parameters. + * Each record is augmented with a new attribute `_highlightResult` which is an + * object keyed by attribute and contains additional properties + * https://community.algolia.com/algoliasearch-helper-js/reference.html#SearchResults#hits + */ +export type Hit = TDoc & { + objectID: string; + '_highlightResult': HighlightResult; +}; + +export type HighlightResult = + TDoc extends { [k: string]: any } ? + { [K in keyof TDoc]: HighlightResultField } : + never; + +export type HighlightResultField = + TField extends Array ? + HighlightResultArray : + TField extends string ? + HighlightResultPrimitive : + HighlightResult; + +export type HighlightResultArray = + TItem extends string ? + HighlightResultPrimitive[] : + Array>; + +export interface HighlightResultPrimitive { + /** the value of the facet highlighted (html) */ + value: string; + /** full, partial or none depending on how the query terms match */ + matchLevel: 'none' | 'partial' | 'full'; + matchedWords: string[]; + fullyHighlighted?: boolean; +} + +/* Hits example: +{ + "title": "Video 3: Nine Characteristics Of A Great Group", + "type": "video", + "tags": [], + "blurb": null, + "security_level": { + "id": 1, + "name": "Anonymous", + "key": "anonymous" + }, + "asset": {}, + "external_asset": "http://vimeo.com/104767570", + "objectID": "t6qPLQCVNesY84OoikkiW", + "_highlightResult": { + "title": { + "value": + "Video 3: Nine Characteristics Of A Great Group", + "matchLevel": "full", + "fullyHighlighted": false, + "matchedWords": ["3"] }, - configure: { - aroundLatLng: boolean, - [key: string]: any + "type": { + "value": "video", + "matchLevel": "none", + "matchedWords": [] }, - refinementList: { - [key: string]: string[] - }, - hierarchicalMenu: { - [key: string]: string - }, - menu: { - [key: string]: string - }, - multiRange: { - [key: string]: string - }, - toggle: { - [key: string]: boolean - }, - hitsPerPage: number, - sortBy: string, - query: string, - page: number, - - indices?: { - [index: string]: { - configure: { - hitsPerPage: number, - }, - } - }, - } - - /** - * The most basic possible document in an Algolia index: - * a set of string-value pairs. - */ - export type BasicDoc = { [k: string]: string } - - /** - * The shape of the searchResults object provided - * via connectors - * https://community.algolia.com/algoliasearch-helper-js/reference.html#searchresults - */ - export interface ISearchResults { - query: string, - hits: Array>, - index: string, - hitsPerPage: number, - nbHits: number, - nbPages: number, - page: number, - processingTimeMS: number, - exhaustiveNbHits: true, - disjunctiveFacets: any[], - hierarchicalFacets: any[], - facets: any[], - aroundLatLng?: string - automaticRadius?: string - } - - /** - * All the records that match the search parameters. - * Each record is augmented with a new attribute `_highlightResult` which is an - * object keyed by attribute and contains additional properties - * https://community.algolia.com/algoliasearch-helper-js/reference.html#SearchResults#hits - */ - type Hit = TDoc & { - objectID: string, - '_highlightResult': HighlightResult, - } - - type HighlightResult = - TDoc extends { [k: string]: any } ? - { [K in keyof TDoc]: HighlightResultField } : - never - - type HighlightResultField = - TField extends Array ? - HighlightResultArray : - TField extends string ? - HighlightResultPrimitive : - HighlightResult - - type HighlightResultArray = - TItem extends string ? - HighlightResultPrimitive[] : - Array> - - type HighlightResultPrimitive = { - /** the value of the facet highlighted (html) */ - value: string, - /** full, partial or none depending on how the query terms match */ - matchLevel: 'none' | 'partial' | 'full', - matchedWords: string[], - fullyHighlighted?: boolean, - } - - /* Hits example: - { - "title": "Video 3: Nine Characteristics Of A Great Group", - "type": "video", - "tags": [], - "blurb": null, "security_level": { - "id": 1, - "name": "Anonymous", - "key": "anonymous" + "name": { + "value": "Anonymous", + "matchLevel": "none", + "matchedWords": [] + }, + "key": { + "value": "anonymous", + "matchLevel": "none", + "matchedWords": [] + } }, - "asset": {}, - "external_asset": "http://vimeo.com/104767570", - "objectID": "t6qPLQCVNesY84OoikkiW", - "_highlightResult": { - "title": { - "value": - "Video 3: Nine Characteristics Of A Great Group", - "matchLevel": "full", - "fullyHighlighted": false, - "matchedWords": ["3"] + "external_asset": { + "value": "http://vimeo.com/104767570", + "matchLevel": "none", + "matchedWords": [] + }, + "asset": { + "sys": { + "locale": { + "value": "en-US", + "matchLevel": "none", + "matchedWords": [] + }, + "space": { + "sys": { + "type": { + "value": "Link", + "matchLevel": "none", + "matchedWords": [] + }, + "linkType": { + "value": "Space", + "matchLevel": "none", + "matchedWords": [] + }, + "id": { + "value": "7yx6ovlj39n5", + "matchLevel": "none", + "matchedWords": [] + } + } + }, + "id": { + "value": "1AXqjzjSN2u0qgMWCW8uG8", + "matchLevel": "none", + "matchedWords": [] }, "type": { - "value": "video", + "value": "Asset", "matchLevel": "none", "matchedWords": [] }, - "security_level": { - "name": { - "value": "Anonymous", - "matchLevel": "none", - "matchedWords": [] - }, - "key": { - "value": "anonymous", - "matchLevel": "none", - "matchedWords": [] - } - }, - "external_asset": { - "value": "http://vimeo.com/104767570", + "createdAt": { + "value": "2018-06-22T02:42:32.632Z", "matchLevel": "none", "matchedWords": [] }, - "asset": { + "updatedAt": { + "value": "2018-06-22T02:42:32.632Z", + "matchLevel": "none", + "matchedWords": [] + }, + "environment": { "sys": { - "locale": { - "value": "en-US", - "matchLevel": "none", - "matchedWords": [] - }, - "space": { - "sys": { - "type": { - "value": "Link", - "matchLevel": "none", - "matchedWords": [] - }, - "linkType": { - "value": "Space", - "matchLevel": "none", - "matchedWords": [] - }, - "id": { - "value": "7yx6ovlj39n5", - "matchLevel": "none", - "matchedWords": [] - } - } - }, - "id": { - "value": "1AXqjzjSN2u0qgMWCW8uG8", - "matchLevel": "none", - "matchedWords": [] - }, - "type": { - "value": "Asset", - "matchLevel": "none", - "matchedWords": [] - }, - "createdAt": { - "value": "2018-06-22T02:42:32.632Z", - "matchLevel": "none", - "matchedWords": [] - }, - "updatedAt": { - "value": "2018-06-22T02:42:32.632Z", - "matchLevel": "none", - "matchedWords": [] - }, - "environment": { - "sys": { - "id": { - "value": "master", - "matchLevel": "none", - "matchedWords": [] - }, - "type": { - "value": "Link", - "matchLevel": "none", - "matchedWords": [] - }, - "linkType": { - "value": "Environment", - "matchLevel": "none", - "matchedWords": [] - } - } - } - }, - "fields": { - "title": { - "value": - "how-to-confess-an-inventory", - "matchLevel": "full", - "fullyHighlighted": false, - "matchedWords": ["confess", "inventory"] - }, - "file": { - "url": { - "value": - "//assets.ctfassets.net/7yx6ovlj39n5/1AXqjzjSN2u0qgMWCW8uG8/3f598700fa730fe03676130328f8b766/how-to-confess-an-inventory.docx", - "matchLevel": "full", - "fullyHighlighted": false, - "matchedWords": ["confess", "inventory"] + "id": { + "value": "master", + "matchLevel": "none", + "matchedWords": [] }, - "fileName": { - "value": - "how-to-confess-an-inventory.docx", - "matchLevel": "full", - "fullyHighlighted": false, - "matchedWords": ["confess", "inventory"] + "type": { + "value": "Link", + "matchLevel": "none", + "matchedWords": [] }, - "contentType": { - "value": - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "linkType": { + "value": "Environment", "matchLevel": "none", "matchedWords": [] } } } + }, + "fields": { + "title": { + "value": + "how-to-confess-an-inventory", + "matchLevel": "full", + "fullyHighlighted": false, + "matchedWords": ["confess", "inventory"] + }, + "file": { + "url": { + "value": + "//assets.ctfassets.net/how-to-confess-an-inventory.docx", + "matchLevel": "full", + "fullyHighlighted": false, + "matchedWords": ["confess", "inventory"] + }, + "fileName": { + "value": + "how-to-confess-an-inventory.docx", + "matchLevel": "full", + "fullyHighlighted": false, + "matchedWords": ["confess", "inventory"] + }, + "contentType": { + "value": + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "matchLevel": "none", + "matchedWords": [] + } + } } - }*/ -} \ No newline at end of file + } +}*/