algoliasearch-helper 3.6.2 → 3.7.2

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/index.d.ts CHANGED
@@ -13,13 +13,13 @@ import algoliasearch, {
13
13
  // @ts-ignore
14
14
  Response as SearchResponseV3,
15
15
  } from 'algoliasearch';
16
- import {
16
+ import {
17
17
  SearchOptions as SearchOptionsV4,
18
18
  SearchResponse as SearchResponseV4,
19
19
  FindAnswersResponse
20
20
  // @ts-ignore
21
21
  } from '@algolia/client-search';
22
- import { EventEmitter } from 'events';
22
+ import EventEmitter from '@algolia/events';
23
23
 
24
24
  type DummySearchClientV4 = {
25
25
  transporter: any;
@@ -1144,8 +1144,16 @@ declare namespace algoliasearchHelper {
1144
1144
  type Operator = '=' | '>' | '>=' | '<' | '<=' | '!=';
1145
1145
  }
1146
1146
 
1147
+ export interface SearchResultsOptions {
1148
+ /**
1149
+ * Marker which can be added to search results to identify them as created without a search response.
1150
+ * This is for internal use, e.g., avoiding caching in infinite hits, or delaying the display of these results.
1151
+ */
1152
+ __isArtificial: boolean | undefined
1153
+ }
1154
+
1147
1155
  export class SearchResults<T = any>
1148
- implements Omit<SearchResponse<T>, 'facets' | 'params'> {
1156
+ implements Omit<SearchResponse<T>, 'facets' | 'params'>, implements SearchResultsOptions {
1149
1157
  /**
1150
1158
  * query used to generate the results
1151
1159
  */
@@ -1298,7 +1306,17 @@ declare namespace algoliasearchHelper {
1298
1306
  _rawResults: SearchResponse<T>[];
1299
1307
  _state: SearchParameters;
1300
1308
 
1301
- constructor(state: SearchParameters, results: SearchResponse<T>[]);
1309
+ /**
1310
+ * Marker which can be added to search results to identify them as created without a search response.
1311
+ * This is for internal use, e.g., avoiding caching in infinite hits, or delaying the display of these results.
1312
+ */
1313
+ // __isArtificial?: boolean;
1314
+
1315
+ constructor(
1316
+ state: SearchParameters,
1317
+ results: SearchResponse<T>[],
1318
+ options?: SearchResultsOptions
1319
+ );
1302
1320
 
1303
1321
  /**
1304
1322
  * Get a facet object with its name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "algoliasearch-helper",
3
- "version": "3.6.2",
3
+ "version": "3.7.2",
4
4
  "description": "Helper for implementing advanced search features with algolia",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -97,7 +97,7 @@
97
97
  "yargs": "13.2.4"
98
98
  },
99
99
  "dependencies": {
100
- "events": "^1.1.1"
100
+ "@algolia/events": "^4.0.1"
101
101
  },
102
102
  "peerDependencies": {
103
103
  "algoliasearch": ">= 3.1 < 5"
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var events = require('events');
3
+ var EventEmitter = require('@algolia/events');
4
4
  var inherits = require('../functions/inherits');
5
5
 
6
6
  /**
@@ -19,7 +19,7 @@ function DerivedHelper(mainHelper, fn) {
19
19
  this.lastResults = null;
20
20
  }
21
21
 
22
- inherits(DerivedHelper, events.EventEmitter);
22
+ inherits(DerivedHelper, EventEmitter);
23
23
 
24
24
  /**
25
25
  * Detach this helper from the main helper
@@ -224,7 +224,7 @@ function findMatchingHierarchicalFacetFromAttributeName(
224
224
  }
225
225
  **/
226
226
  /*eslint-enable */
227
- function SearchResults(state, results) {
227
+ function SearchResults(state, results, options) {
228
228
  var mainSubResponse = results[0];
229
229
 
230
230
  this._rawResults = results;
@@ -236,6 +236,11 @@ function SearchResults(state, results) {
236
236
  self[key] = mainSubResponse[key];
237
237
  });
238
238
 
239
+ // Make every key of the result options reachable from the instance
240
+ Object.keys(options || {}).forEach(function(key) {
241
+ self[key] = options[key];
242
+ });
243
+
239
244
  /**
240
245
  * query used to generate the results
241
246
  * @name query
@@ -5,7 +5,7 @@ var SearchResults = require('./SearchResults');
5
5
  var DerivedHelper = require('./DerivedHelper');
6
6
  var requestBuilder = require('./requestBuilder');
7
7
 
8
- var events = require('events');
8
+ var EventEmitter = require('@algolia/events');
9
9
  var inherits = require('./functions/inherits');
10
10
  var objectHasKeys = require('./functions/objectHasKeys');
11
11
  var omit = require('./functions/omit');
@@ -132,7 +132,7 @@ function AlgoliaSearchHelper(client, index, options) {
132
132
  this._currentNbQueries = 0;
133
133
  }
134
134
 
135
- inherits(AlgoliaSearchHelper, events.EventEmitter);
135
+ inherits(AlgoliaSearchHelper, EventEmitter);
136
136
 
137
137
  /**
138
138
  * Start the search with the parameters set in the state. When the
package/src/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict';
2
2
 
3
- module.exports = '3.6.2';
3
+ module.exports = '3.7.2';