instantsearch.js 4.38.1 → 4.39.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # [4.39.0](https://github.com/algolia/instantsearch.js/compare/v4.38.1...v4.39.0) (2022-02-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * **ts:** allow Hits related connectors to be generic ([#5019](https://github.com/algolia/instantsearch.js/issues/5019)) ([e986f7e](https://github.com/algolia/instantsearch.js/commit/e986f7e46d57173da4d3d6c3c23fbdf3f9c0f78c))
7
+
8
+
9
+
1
10
  ## [4.38.1](https://github.com/algolia/instantsearch.js/compare/v4.38.0...v4.38.1) (2022-02-08)
2
11
 
3
12
 
@@ -69,7 +69,8 @@ function extractHitsFromCachedHits(cachedHits) {
69
69
 
70
70
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
71
71
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _index.noop;
72
- (0, _index.checkRendering)(renderFn, withUsage());
72
+ (0, _index.checkRendering)(renderFn, withUsage()); // @TODO: this should be a generic, but a Connector can not yet be generic itself
73
+
73
74
  return function (widgetParams) {
74
75
  var _ref4 = widgetParams || {},
75
76
  _ref4$escapeHTML = _ref4.escapeHTML,
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.38.1';
7
+ var _default = '4.39.0';
8
8
  exports.default = _default;
@@ -12,8 +12,7 @@ import { default as qs_2 } from 'qs';
12
12
  import type { SearchParameters } from 'algoliasearch-helper';
13
13
  import type { SearchResults } from 'algoliasearch-helper';
14
14
 
15
- declare type AlgoliaHit = {
16
- [attribute: string]: any;
15
+ declare type AlgoliaHit<THit extends BaseHit = Record<string, any>> = {
17
16
  objectID: string;
18
17
  _highlightResult?: HitHighlightResult;
19
18
  _snippetResult?: HitSnippetResult;
@@ -36,7 +35,7 @@ declare type AlgoliaHit = {
36
35
  };
37
36
  _distinctSeqID?: number;
38
37
  _geoLoc?: GeoLoc;
39
- };
38
+ } & THit;
40
39
 
41
40
  declare const analytics: AnalyticsWidget;
42
41
 
@@ -292,6 +291,8 @@ declare type AutocompleteWidgetDescription = {
292
291
  };
293
292
  };
294
293
 
294
+ declare type BaseHit = Record<string, unknown>;
295
+
295
296
  declare type BindEventForHits = BuiltInBindEventForHits & CustomBindEventForHits;
296
297
 
297
298
  declare type Bounds = {
@@ -734,11 +735,11 @@ declare const connectHits: HitsConnector;
734
735
 
735
736
  declare const connectHitsPerPage: HitsPerPageConnector;
736
737
 
737
- declare const connectHitsWithInsights: HitsConnector;
738
+ declare const connectHitsWithInsights: HitsConnector<BaseHit>;
738
739
 
739
740
  declare const connectInfiniteHits: InfiniteHitsConnector;
740
741
 
741
- declare const connectInfiniteHitsWithInsights: InfiniteHitsConnector;
742
+ declare const connectInfiniteHitsWithInsights: InfiniteHitsConnector<BaseHit>;
742
743
 
743
744
  /**
744
745
  * **Menu** connector provides the logic to build a widget that will give the user the ability to choose a single value for a specific facet. The typical usage of menu is for navigation in categories.
@@ -1760,10 +1761,10 @@ declare type HighlightOptions = {
1760
1761
 
1761
1762
  declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1762
1763
 
1763
- declare type Hit = {
1764
+ declare type Hit<THit extends BaseHit = Record<string, any>> = {
1764
1765
  __position: number;
1765
1766
  __queryID?: string;
1766
- } & AlgoliaHit;
1767
+ } & AlgoliaHit<THit>;
1767
1768
 
1768
1769
  declare type HitAttributeHighlightResult = {
1769
1770
  value: string;
@@ -1778,13 +1779,16 @@ declare type HitHighlightResult = {
1778
1779
  [attribute: string]: HitAttributeHighlightResult | HitAttributeHighlightResult[] | HitHighlightResult[] | HitHighlightResult;
1779
1780
  };
1780
1781
 
1782
+ /**
1783
+ * @deprecated use Hit[] directly instead
1784
+ */
1781
1785
  declare type Hits = Hit[];
1782
1786
 
1783
1787
  declare const hits: HitsWidget;
1784
1788
 
1785
- declare type HitsConnector = Connector<HitsWidgetDescription, HitsConnectorParams>;
1789
+ declare type HitsConnector<THit extends BaseHit = BaseHit> = Connector<HitsWidgetDescription<THit>, HitsConnectorParams<THit>>;
1786
1790
 
1787
- declare type HitsConnectorParams = {
1791
+ declare type HitsConnectorParams<THit extends BaseHit = BaseHit> = {
1788
1792
  /**
1789
1793
  * Whether to escape HTML tags from hits string values.
1790
1794
  *
@@ -1794,7 +1798,7 @@ declare type HitsConnectorParams = {
1794
1798
  /**
1795
1799
  * Function to transform the items passed to the templates.
1796
1800
  */
1797
- transformItems?: TransformItems<Hit>;
1801
+ transformItems?: TransformItems<Hit<THit>>;
1798
1802
  };
1799
1803
 
1800
1804
  declare type HitsCSSClasses = Partial<{
@@ -1923,15 +1927,15 @@ declare type HitsPerPageWidgetParams = {
1923
1927
  cssClasses?: HitsPerPageCSSClasses;
1924
1928
  };
1925
1929
 
1926
- declare type HitsRenderState = {
1930
+ declare type HitsRenderState<THit extends BaseHit = BaseHit> = {
1927
1931
  /**
1928
1932
  * The matched hits from Algolia API.
1929
1933
  */
1930
- hits: Hits;
1934
+ hits: Array<Hit<THit>>;
1931
1935
  /**
1932
1936
  * The response from the Algolia API.
1933
1937
  */
1934
- results?: SearchResults<Hit>;
1938
+ results?: SearchResults<Hit<THit>>;
1935
1939
  /**
1936
1940
  * Sends an event to the Insights middleware.
1937
1941
  */
@@ -1963,11 +1967,11 @@ declare type HitsWidget = WidgetFactory<HitsWidgetDescription & {
1963
1967
  $$widgetType: 'ais.hits';
1964
1968
  }, HitsConnectorParams, HitsWidgetParams>;
1965
1969
 
1966
- declare type HitsWidgetDescription = {
1970
+ declare type HitsWidgetDescription<THit extends BaseHit = BaseHit> = {
1967
1971
  $$type: 'ais.hits';
1968
- renderState: HitsRenderState;
1972
+ renderState: HitsRenderState<THit>;
1969
1973
  indexRenderState: {
1970
- hits: WidgetRenderState<HitsRenderState, HitsConnectorParams>;
1974
+ hits: WidgetRenderState<HitsRenderState<THit>, HitsConnectorParams<THit>>;
1971
1975
  };
1972
1976
  };
1973
1977
 
@@ -2048,18 +2052,18 @@ declare type IndexWidgetParams = {
2048
2052
 
2049
2053
  declare const infiniteHits: InfiniteHitsWidget;
2050
2054
 
2051
- declare type InfiniteHitsCache = {
2052
- read: Read;
2053
- write: Write;
2055
+ declare type InfiniteHitsCache<THit extends BaseHit = BaseHit> = {
2056
+ read: Read<THit>;
2057
+ write: Write<THit>;
2054
2058
  };
2055
2059
 
2056
- declare type InfiniteHitsCachedHits = {
2057
- [page: number]: Hits;
2060
+ declare type InfiniteHitsCachedHits<THit extends BaseHit> = {
2061
+ [page: number]: Array<Hit<THit>>;
2058
2062
  };
2059
2063
 
2060
- declare type InfiniteHitsConnector = Connector<InfiniteHitsWidgetDescription, InfiniteHitsConnectorParams>;
2064
+ declare type InfiniteHitsConnector<THit extends BaseHit = BaseHit> = Connector<InfiniteHitsWidgetDescription<THit>, InfiniteHitsConnectorParams<THit>>;
2061
2065
 
2062
- declare type InfiniteHitsConnectorParams = {
2066
+ declare type InfiniteHitsConnectorParams<THit extends BaseHit = BaseHit> = {
2063
2067
  /**
2064
2068
  * Escapes HTML entities from hits string values.
2065
2069
  *
@@ -2076,13 +2080,13 @@ declare type InfiniteHitsConnectorParams = {
2076
2080
  * Receives the items, and is called before displaying them.
2077
2081
  * Useful for mapping over the items to transform, and remove or reorder them.
2078
2082
  */
2079
- transformItems?: TransformItems<Hit>;
2083
+ transformItems?: TransformItems<Hit<THit>>;
2080
2084
  /**
2081
2085
  * Reads and writes hits from/to cache.
2082
2086
  * When user comes back to the search page after leaving for product page,
2083
2087
  * this helps restore InfiniteHits and its scroll position.
2084
2088
  */
2085
- cache?: InfiniteHitsCache;
2089
+ cache?: InfiniteHitsCache<THit>;
2086
2090
  };
2087
2091
 
2088
2092
  declare type InfiniteHitsCSSClasses = Partial<{
@@ -2120,7 +2124,7 @@ declare type InfiniteHitsCSSClasses = Partial<{
2120
2124
  disabledLoadMore: string | string[];
2121
2125
  }>;
2122
2126
 
2123
- declare type InfiniteHitsRenderState = {
2127
+ declare type InfiniteHitsRenderState<THit extends BaseHit = BaseHit> = {
2124
2128
  /**
2125
2129
  * Loads the previous results.
2126
2130
  */
@@ -2148,15 +2152,15 @@ declare type InfiniteHitsRenderState = {
2148
2152
  /**
2149
2153
  * Hits for the current page
2150
2154
  */
2151
- currentPageHits: Hits;
2155
+ currentPageHits: Array<Hit<THit>>;
2152
2156
  /**
2153
2157
  * Hits for current and cached pages
2154
2158
  */
2155
- hits: Hits;
2159
+ hits: Array<Hit<THit>>;
2156
2160
  /**
2157
2161
  * The response from the Algolia API.
2158
2162
  */
2159
- results?: SearchResults<Hit>;
2163
+ results?: SearchResults<Hit<THit>>;
2160
2164
  };
2161
2165
 
2162
2166
  declare type InfiniteHitsTemplates = Partial<{
@@ -2186,11 +2190,11 @@ declare type InfiniteHitsWidget = WidgetFactory<InfiniteHitsWidgetDescription &
2186
2190
  $$widgetType: 'ais.infiniteHits';
2187
2191
  }, InfiniteHitsConnectorParams, InfiniteHitsWidgetParams>;
2188
2192
 
2189
- declare type InfiniteHitsWidgetDescription = {
2193
+ declare type InfiniteHitsWidgetDescription<THit extends BaseHit = BaseHit> = {
2190
2194
  $$type: 'ais.infiniteHits';
2191
- renderState: InfiniteHitsRenderState;
2195
+ renderState: InfiniteHitsRenderState<THit>;
2192
2196
  indexRenderState: {
2193
- infiniteHits: WidgetRenderState<InfiniteHitsRenderState, InfiniteHitsConnectorParams>;
2197
+ infiniteHits: WidgetRenderState<InfiniteHitsRenderState<THit>, InfiniteHitsConnectorParams<THit>>;
2194
2198
  };
2195
2199
  indexUiState: {
2196
2200
  page: number;
@@ -3807,9 +3811,9 @@ declare type RatingMenuWidgetParams = {
3807
3811
  cssClasses?: RatingMenuCSSClasses;
3808
3812
  };
3809
3813
 
3810
- declare type Read = ({ state, }: {
3814
+ declare type Read<THit extends BaseHit> = ({ state, }: {
3811
3815
  state: PlainSearchParameters;
3812
- }) => InfiniteHitsCachedHits | null;
3816
+ }) => InfiniteHitsCachedHits<THit> | null;
3813
3817
 
3814
3818
  declare type ReconfigurableOptions = Places.ReconfigurableOptions;
3815
3819
 
@@ -5251,9 +5255,9 @@ declare type WidgetType<TWidgetDescription extends WidgetDescription> = TWidgetD
5251
5255
 
5252
5256
  declare type WidgetUiStates = PlacesWidgetDescription['indexUiState'];
5253
5257
 
5254
- declare type Write = ({ state, hits, }: {
5258
+ declare type Write<THit extends BaseHit> = ({ state, hits, }: {
5255
5259
  state: PlainSearchParameters;
5256
- hits: InfiniteHitsCachedHits;
5260
+ hits: InfiniteHitsCachedHits<THit>;
5257
5261
  }) => void;
5258
5262
 
5259
5263
  export { }
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.38.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.39.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -8483,7 +8483,7 @@
8483
8483
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8484
8484
  }
8485
8485
 
8486
- var version$1 = '4.38.1';
8486
+ var version$1 = '4.39.0';
8487
8487
 
8488
8488
  var NAMESPACE = 'ais';
8489
8489
  var component = function component(componentName) {
@@ -11547,7 +11547,8 @@
11547
11547
 
11548
11548
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
11549
11549
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11550
- checkRendering(renderFn, withUsage$7());
11550
+ checkRendering(renderFn, withUsage$7()); // @TODO: this should be a generic, but a Connector can not yet be generic itself
11551
+
11551
11552
  return function (widgetParams) {
11552
11553
  var _ref4 = widgetParams || {},
11553
11554
  _ref4$escapeHTML = _ref4.escapeHTML,