@algolia/client-search 5.0.0-alpha.2 → 5.0.0-alpha.20

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.
Files changed (302) hide show
  1. package/dist/builds/browser.d.ts +2 -2
  2. package/dist/builds/browser.d.ts.map +1 -1
  3. package/dist/builds/node.d.ts +2 -2
  4. package/dist/builds/node.d.ts.map +1 -1
  5. package/dist/client-search.cjs.js +163 -38
  6. package/dist/client-search.esm.browser.js +192 -67
  7. package/dist/client-search.esm.node.js +164 -39
  8. package/dist/client-search.umd.js +2 -2
  9. package/dist/model/acl.d.ts +3 -0
  10. package/dist/model/acl.d.ts.map +1 -1
  11. package/dist/model/action.d.ts.map +1 -1
  12. package/dist/model/addApiKeyResponse.d.ts +1 -1
  13. package/dist/model/addApiKeyResponse.d.ts.map +1 -1
  14. package/dist/model/advancedSyntaxFeatures.d.ts.map +1 -1
  15. package/dist/model/alternativesAsExact.d.ts.map +1 -1
  16. package/dist/model/anchoring.d.ts.map +1 -1
  17. package/dist/model/apiKey.d.ts.map +1 -1
  18. package/dist/model/aroundRadius.d.ts.map +1 -1
  19. package/dist/model/aroundRadiusAll.d.ts.map +1 -1
  20. package/dist/model/assignUserIdParams.d.ts.map +1 -1
  21. package/dist/model/attributeToUpdate.d.ts +3 -0
  22. package/dist/model/attributeToUpdate.d.ts.map +1 -0
  23. package/dist/model/automaticFacetFilter.d.ts.map +1 -1
  24. package/dist/model/automaticFacetFilters.d.ts.map +1 -1
  25. package/dist/model/baseGetApiKeyResponse.d.ts +11 -0
  26. package/dist/model/baseGetApiKeyResponse.d.ts.map +1 -0
  27. package/dist/model/baseIndexSettings.d.ts +4 -0
  28. package/dist/model/baseIndexSettings.d.ts.map +1 -1
  29. package/dist/model/baseSearchParams.d.ts.map +1 -1
  30. package/dist/model/baseSearchParamsWithoutQuery.d.ts.map +1 -1
  31. package/dist/model/baseSearchResponse.d.ts +1 -1
  32. package/dist/model/baseSearchResponse.d.ts.map +1 -1
  33. package/dist/model/batchAssignUserIdsParams.d.ts.map +1 -1
  34. package/dist/model/batchDictionaryEntriesParams.d.ts.map +1 -1
  35. package/dist/model/batchDictionaryEntriesRequest.d.ts.map +1 -1
  36. package/dist/model/batchParams.d.ts +2 -2
  37. package/dist/model/batchParams.d.ts.map +1 -1
  38. package/dist/model/batchRequest.d.ts +9 -0
  39. package/dist/model/batchRequest.d.ts.map +1 -0
  40. package/dist/model/batchResponse.d.ts.map +1 -1
  41. package/dist/model/batchWriteParams.d.ts +2 -2
  42. package/dist/model/batchWriteParams.d.ts.map +1 -1
  43. package/dist/model/browseParams.d.ts +4 -0
  44. package/dist/model/browseParams.d.ts.map +1 -0
  45. package/dist/model/browseParamsObject.d.ts +4 -0
  46. package/dist/model/browseParamsObject.d.ts.map +1 -0
  47. package/dist/model/browseResponse.d.ts +2 -2
  48. package/dist/model/browseResponse.d.ts.map +1 -1
  49. package/dist/model/builtInOperation.d.ts.map +1 -1
  50. package/dist/model/builtInOperationType.d.ts.map +1 -1
  51. package/dist/model/clientMethodProps.d.ts +26 -14
  52. package/dist/model/clientMethodProps.d.ts.map +1 -1
  53. package/dist/model/condition.d.ts.map +1 -1
  54. package/dist/model/consequence.d.ts.map +1 -1
  55. package/dist/model/consequenceHide.d.ts.map +1 -1
  56. package/dist/model/consequenceParams.d.ts.map +1 -1
  57. package/dist/model/consequenceQuery.d.ts.map +1 -1
  58. package/dist/model/consequenceQueryObject.d.ts.map +1 -1
  59. package/dist/model/createdAtResponse.d.ts.map +1 -1
  60. package/dist/model/{baseBrowseResponse.d.ts → cursor.d.ts} +3 -3
  61. package/dist/model/cursor.d.ts.map +1 -0
  62. package/dist/model/deleteApiKeyResponse.d.ts.map +1 -1
  63. package/dist/model/deleteByParams.d.ts +27 -0
  64. package/dist/model/deleteByParams.d.ts.map +1 -0
  65. package/dist/model/deleteSourceResponse.d.ts.map +1 -1
  66. package/dist/model/deletedAtResponse.d.ts.map +1 -1
  67. package/dist/model/dictionaryAction.d.ts.map +1 -1
  68. package/dist/model/dictionaryEntry.d.ts.map +1 -1
  69. package/dist/model/dictionaryEntryState.d.ts.map +1 -1
  70. package/dist/model/dictionaryLanguage.d.ts.map +1 -1
  71. package/dist/model/dictionarySettingsParams.d.ts.map +1 -1
  72. package/dist/model/dictionaryType.d.ts.map +1 -1
  73. package/dist/model/distinct.d.ts +5 -0
  74. package/dist/model/distinct.d.ts.map +1 -0
  75. package/dist/model/edit.d.ts.map +1 -1
  76. package/dist/model/editType.d.ts.map +1 -1
  77. package/dist/model/errorBase.d.ts.map +1 -1
  78. package/dist/model/exactOnSingleWordQuery.d.ts.map +1 -1
  79. package/dist/model/facetFilters.d.ts.map +1 -1
  80. package/dist/model/facetHits.d.ts.map +1 -1
  81. package/dist/model/facetOrdering.d.ts.map +1 -1
  82. package/dist/model/facets.d.ts.map +1 -1
  83. package/dist/model/facetsStats.d.ts.map +1 -1
  84. package/dist/model/fetchedIndex.d.ts.map +1 -1
  85. package/dist/model/getApiKeyResponse.d.ts +4 -0
  86. package/dist/model/getApiKeyResponse.d.ts.map +1 -0
  87. package/dist/model/getDictionarySettingsResponse.d.ts.map +1 -1
  88. package/dist/model/getLogsResponse.d.ts.map +1 -1
  89. package/dist/model/getObjectsParams.d.ts +2 -2
  90. package/dist/model/getObjectsParams.d.ts.map +1 -1
  91. package/dist/model/{multipleGetObjectsParams.d.ts → getObjectsRequest.d.ts} +2 -2
  92. package/dist/model/getObjectsRequest.d.ts.map +1 -0
  93. package/dist/model/getObjectsResponse.d.ts +2 -2
  94. package/dist/model/getObjectsResponse.d.ts.map +1 -1
  95. package/dist/model/getTaskResponse.d.ts.map +1 -1
  96. package/dist/model/getTopUserIdsResponse.d.ts.map +1 -1
  97. package/dist/model/hasPendingMappingsResponse.d.ts.map +1 -1
  98. package/dist/model/highlightResult.d.ts.map +1 -1
  99. package/dist/model/highlightResultOption.d.ts.map +1 -1
  100. package/dist/model/hit.d.ts +1 -1
  101. package/dist/model/hit.d.ts.map +1 -1
  102. package/dist/model/ignorePlurals.d.ts.map +1 -1
  103. package/dist/model/index.d.ts +11 -9
  104. package/dist/model/index.d.ts.map +1 -1
  105. package/dist/model/indexSettings.d.ts.map +1 -1
  106. package/dist/model/indexSettingsAsSearchParams.d.ts +4 -6
  107. package/dist/model/indexSettingsAsSearchParams.d.ts.map +1 -1
  108. package/dist/model/languages.d.ts.map +1 -1
  109. package/dist/model/listApiKeysResponse.d.ts +2 -2
  110. package/dist/model/listApiKeysResponse.d.ts.map +1 -1
  111. package/dist/model/listClustersResponse.d.ts.map +1 -1
  112. package/dist/model/listIndicesResponse.d.ts +1 -1
  113. package/dist/model/listIndicesResponse.d.ts.map +1 -1
  114. package/dist/model/listUserIdsResponse.d.ts.map +1 -1
  115. package/dist/model/log.d.ts.map +1 -1
  116. package/dist/model/logQuery.d.ts.map +1 -1
  117. package/dist/model/logType.d.ts.map +1 -1
  118. package/dist/model/matchLevel.d.ts.map +1 -1
  119. package/dist/model/matchedGeoLocation.d.ts.map +1 -1
  120. package/dist/model/mixedSearchFilters.d.ts.map +1 -1
  121. package/dist/model/{multipleBatchOperation.d.ts → multipleBatchRequest.d.ts} +5 -5
  122. package/dist/model/multipleBatchRequest.d.ts.map +1 -0
  123. package/dist/model/multipleBatchResponse.d.ts +2 -2
  124. package/dist/model/multipleBatchResponse.d.ts.map +1 -1
  125. package/dist/model/numericFilters.d.ts.map +1 -1
  126. package/dist/model/operationIndexParams.d.ts.map +1 -1
  127. package/dist/model/operationType.d.ts.map +1 -1
  128. package/dist/model/optionalFilters.d.ts.map +1 -1
  129. package/dist/model/params.d.ts.map +1 -1
  130. package/dist/model/personalization.d.ts.map +1 -1
  131. package/dist/model/promote.d.ts.map +1 -1
  132. package/dist/model/promoteObjectID.d.ts.map +1 -1
  133. package/dist/model/promoteObjectIDs.d.ts.map +1 -1
  134. package/dist/model/queryType.d.ts.map +1 -1
  135. package/dist/model/rankingInfo.d.ts.map +1 -1
  136. package/dist/model/reRankingApplyFilter.d.ts.map +1 -1
  137. package/dist/model/removeStopWords.d.ts.map +1 -1
  138. package/dist/model/removeUserIdResponse.d.ts.map +1 -1
  139. package/dist/model/removeWordsIfNoResults.d.ts.map +1 -1
  140. package/dist/model/renderingContent.d.ts.map +1 -1
  141. package/dist/model/replaceSourceResponse.d.ts.map +1 -1
  142. package/dist/model/rule.d.ts.map +1 -1
  143. package/dist/model/saveObjectResponse.d.ts +2 -2
  144. package/dist/model/saveObjectResponse.d.ts.map +1 -1
  145. package/dist/model/saveSynonymResponse.d.ts.map +1 -1
  146. package/dist/model/scopeType.d.ts.map +1 -1
  147. package/dist/model/searchDictionaryEntriesParams.d.ts.map +1 -1
  148. package/dist/model/searchForFacetValuesRequest.d.ts.map +1 -1
  149. package/dist/model/searchForFacetValuesResponse.d.ts.map +1 -1
  150. package/dist/model/searchForFacets.d.ts.map +1 -1
  151. package/dist/model/searchForFacetsOptions.d.ts.map +1 -1
  152. package/dist/model/searchForHits.d.ts.map +1 -1
  153. package/dist/model/searchForHitsOptions.d.ts.map +1 -1
  154. package/dist/model/searchHits.d.ts +1 -1
  155. package/dist/model/searchHits.d.ts.map +1 -1
  156. package/dist/model/searchMethodParams.d.ts.map +1 -1
  157. package/dist/model/searchParams.d.ts.map +1 -1
  158. package/dist/model/searchParamsObject.d.ts.map +1 -1
  159. package/dist/model/searchParamsQuery.d.ts.map +1 -1
  160. package/dist/model/searchParamsString.d.ts.map +1 -1
  161. package/dist/model/searchQuery.d.ts.map +1 -1
  162. package/dist/model/searchResponse.d.ts +1 -1
  163. package/dist/model/searchResponse.d.ts.map +1 -1
  164. package/dist/model/searchResponses.d.ts +1 -1
  165. package/dist/model/searchResponses.d.ts.map +1 -1
  166. package/dist/model/searchRulesParams.d.ts.map +1 -1
  167. package/dist/model/searchRulesResponse.d.ts.map +1 -1
  168. package/dist/model/searchStrategy.d.ts.map +1 -1
  169. package/dist/model/searchSynonymsParams.d.ts.map +1 -1
  170. package/dist/model/searchSynonymsResponse.d.ts.map +1 -1
  171. package/dist/model/searchTypeDefault.d.ts.map +1 -1
  172. package/dist/model/searchTypeFacet.d.ts.map +1 -1
  173. package/dist/model/searchUserIdsParams.d.ts.map +1 -1
  174. package/dist/model/searchUserIdsResponse.d.ts.map +1 -1
  175. package/dist/model/snippetResult.d.ts.map +1 -1
  176. package/dist/model/snippetResultOption.d.ts.map +1 -1
  177. package/dist/model/sortRemainingBy.d.ts.map +1 -1
  178. package/dist/model/source.d.ts.map +1 -1
  179. package/dist/model/standardEntries.d.ts.map +1 -1
  180. package/dist/model/synonymHit.d.ts +0 -2
  181. package/dist/model/synonymHit.d.ts.map +1 -1
  182. package/dist/model/synonymType.d.ts.map +1 -1
  183. package/dist/model/tagFilters.d.ts.map +1 -1
  184. package/dist/model/taskStatus.d.ts.map +1 -1
  185. package/dist/model/timeRange.d.ts.map +1 -1
  186. package/dist/model/typoTolerance.d.ts.map +1 -1
  187. package/dist/model/typoToleranceEnum.d.ts.map +1 -1
  188. package/dist/model/updateApiKeyResponse.d.ts +1 -1
  189. package/dist/model/updateApiKeyResponse.d.ts.map +1 -1
  190. package/dist/model/updatedAtResponse.d.ts.map +1 -1
  191. package/dist/model/updatedAtWithObjectIdResponse.d.ts.map +1 -1
  192. package/dist/model/updatedRuleResponse.d.ts.map +1 -1
  193. package/dist/model/userHighlightResult.d.ts.map +1 -1
  194. package/dist/model/userHit.d.ts.map +1 -1
  195. package/dist/model/userId.d.ts.map +1 -1
  196. package/dist/model/value.d.ts.map +1 -1
  197. package/dist/src/searchClient.d.ts +71 -24
  198. package/dist/src/searchClient.d.ts.map +1 -1
  199. package/model/acl.ts +3 -0
  200. package/model/addApiKeyResponse.ts +2 -1
  201. package/model/apiKey.ts +7 -0
  202. package/model/{attributeOrBuiltInOperation.ts → attributeToUpdate.ts} +1 -1
  203. package/model/automaticFacetFilter.ts +2 -0
  204. package/model/baseGetApiKeyResponse.ts +13 -0
  205. package/model/baseIndexSettings.ts +18 -0
  206. package/model/baseSearchParamsWithoutQuery.ts +32 -0
  207. package/model/baseSearchResponse.ts +25 -1
  208. package/model/batchAssignUserIdsParams.ts +1 -0
  209. package/model/batchDictionaryEntriesParams.ts +1 -0
  210. package/model/batchDictionaryEntriesRequest.ts +1 -0
  211. package/model/batchParams.ts +2 -2
  212. package/model/{batchOperation.ts → batchRequest.ts} +4 -3
  213. package/model/batchResponse.ts +1 -0
  214. package/model/batchWriteParams.ts +2 -2
  215. package/model/browseParams.ts +6 -0
  216. package/model/browseParamsObject.ts +6 -0
  217. package/model/browseResponse.ts +3 -3
  218. package/model/builtInOperation.ts +1 -0
  219. package/model/clientMethodProps.ts +31 -19
  220. package/model/condition.ts +3 -0
  221. package/model/consequence.ts +4 -0
  222. package/model/consequenceQueryObject.ts +1 -0
  223. package/model/{baseBrowseResponse.ts → cursor.ts} +2 -2
  224. package/model/deleteByParams.ts +36 -0
  225. package/model/deletedAtResponse.ts +1 -0
  226. package/model/dictionaryEntry.ts +5 -0
  227. package/model/{createdAtObject.ts → distinct.ts} +4 -6
  228. package/model/edit.ts +2 -0
  229. package/model/facetHits.ts +2 -0
  230. package/model/facetOrdering.ts +1 -0
  231. package/model/facetsStats.ts +3 -0
  232. package/model/fetchedIndex.ts +10 -0
  233. package/model/{key.ts → getApiKeyResponse.ts} +2 -2
  234. package/model/getObjectsParams.ts +2 -2
  235. package/model/{multipleGetObjectsParams.ts → getObjectsRequest.ts} +3 -1
  236. package/model/getObjectsResponse.ts +2 -2
  237. package/model/hasPendingMappingsResponse.ts +1 -0
  238. package/model/highlightResultOption.ts +3 -0
  239. package/model/hit.ts +5 -1
  240. package/model/index.ts +11 -9
  241. package/model/indexSettingsAsSearchParams.ts +45 -6
  242. package/model/languages.ts +2 -0
  243. package/model/listApiKeysResponse.ts +2 -2
  244. package/model/listIndicesResponse.ts +2 -1
  245. package/model/log.ts +14 -0
  246. package/model/logQuery.ts +2 -0
  247. package/model/matchedGeoLocation.ts +2 -0
  248. package/model/{multipleBatchOperation.ts → multipleBatchRequest.ts} +6 -4
  249. package/model/multipleBatchResponse.ts +3 -2
  250. package/model/operationIndexParams.ts +2 -0
  251. package/model/params.ts +3 -0
  252. package/model/personalization.ts +2 -0
  253. package/model/promoteObjectID.ts +1 -0
  254. package/model/promoteObjectIDs.ts +1 -0
  255. package/model/rankingInfo.ts +12 -0
  256. package/model/rule.ts +5 -0
  257. package/model/saveObjectResponse.ts +4 -2
  258. package/model/saveSynonymResponse.ts +2 -0
  259. package/model/searchDictionaryEntriesParams.ts +3 -0
  260. package/model/searchForFacetValuesRequest.ts +2 -0
  261. package/model/searchForFacetsOptions.ts +4 -0
  262. package/model/searchForHitsOptions.ts +1 -0
  263. package/model/searchHits.ts +1 -1
  264. package/model/searchMethodParams.ts +1 -0
  265. package/model/searchResponse.ts +2 -1
  266. package/model/searchResponses.ts +1 -1
  267. package/model/searchRulesParams.ts +6 -0
  268. package/model/searchRulesResponse.ts +3 -0
  269. package/model/searchSynonymsResponse.ts +1 -0
  270. package/model/searchUserIdsParams.ts +3 -0
  271. package/model/searchUserIdsResponse.ts +4 -0
  272. package/model/snippetResultOption.ts +1 -0
  273. package/model/source.ts +1 -0
  274. package/model/standardEntries.ts +2 -0
  275. package/model/synonymHit.ts +7 -2
  276. package/model/timeRange.ts +1 -0
  277. package/model/updateApiKeyResponse.ts +2 -1
  278. package/model/updatedAtResponse.ts +1 -0
  279. package/model/updatedAtWithObjectIdResponse.ts +2 -0
  280. package/model/updatedRuleResponse.ts +2 -0
  281. package/model/userHighlightResult.ts +1 -0
  282. package/model/userHit.ts +5 -0
  283. package/model/userId.ts +3 -0
  284. package/model/value.ts +1 -0
  285. package/package.json +31 -13
  286. package/dist/model/attributeOrBuiltInOperation.d.ts +0 -3
  287. package/dist/model/attributeOrBuiltInOperation.d.ts.map +0 -1
  288. package/dist/model/baseBrowseResponse.d.ts.map +0 -1
  289. package/dist/model/batchOperation.d.ts +0 -9
  290. package/dist/model/batchOperation.d.ts.map +0 -1
  291. package/dist/model/browseRequest.d.ts +0 -11
  292. package/dist/model/browseRequest.d.ts.map +0 -1
  293. package/dist/model/createdAtObject.d.ts +0 -7
  294. package/dist/model/createdAtObject.d.ts.map +0 -1
  295. package/dist/model/key.d.ts +0 -4
  296. package/dist/model/key.d.ts.map +0 -1
  297. package/dist/model/multipleBatchOperation.d.ts.map +0 -1
  298. package/dist/model/multipleGetObjectsParams.d.ts.map +0 -1
  299. package/dist/model/synonymHitHighlightResult.d.ts +0 -12
  300. package/dist/model/synonymHitHighlightResult.d.ts.map +0 -1
  301. package/model/browseRequest.ts +0 -12
  302. package/model/synonymHitHighlightResult.ts +0 -14
@@ -15,43 +15,43 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
15
15
  };
16
16
  }
17
17
 
18
- const DEFAULT_MAX_RETRIES = 50;
19
- const DEFAULT_TIMEOUT = retryCount => Math.min(retryCount * 200, 5000);
20
18
  /**
21
- * Return a promise that retry a task until it meets the condition.
19
+ * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
22
20
  *
23
- * @param createRetryablePromiseOptions - The createRetryablePromise options.
24
- * @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
25
- * @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
26
- * @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
27
- * @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
21
+ * @param createIterator - The createIterator options.
22
+ * @param createIterator.func - The function to run, which returns a promise.
23
+ * @param createIterator.validate - The validator function. It receives the resolved return of `func`.
24
+ * @param createIterator.aggregator - The function that runs right after the `func` method has been executed, allows you to do anything with the response before `validate`.
25
+ * @param createIterator.error - The `validate` condition to throw an error, and its message.
26
+ * @param createIterator.timeout - The function to decide how long to wait between iterations.
28
27
  */
29
-
30
- function createRetryablePromise({
28
+ function createIterablePromise({
31
29
  func,
32
30
  validate,
33
- maxRetries = DEFAULT_MAX_RETRIES,
34
- timeout = DEFAULT_TIMEOUT
31
+ aggregator,
32
+ error,
33
+ timeout = () => 0
35
34
  }) {
36
- let retryCount = 0;
37
-
38
- const retry = () => {
35
+ const retry = previousResponse => {
39
36
  return new Promise((resolve, reject) => {
40
- func().then(response => {
41
- const isValid = validate(response);
37
+ func(previousResponse).then(response => {
38
+ if (aggregator) {
39
+ aggregator(response);
40
+ }
42
41
 
43
- if (isValid) {
44
- resolve(response);
45
- } else if (retryCount + 1 >= maxRetries) {
46
- reject(new Error(`The maximum number of retries exceeded. (${retryCount + 1}/${maxRetries})`));
47
- } else {
48
- retryCount += 1;
49
- setTimeout(() => {
50
- retry().then(resolve).catch(reject);
51
- }, timeout(retryCount));
42
+ if (validate(response)) {
43
+ return resolve(response);
52
44
  }
53
- }).catch(error => {
54
- reject(error);
45
+
46
+ if (error && error.validate(response)) {
47
+ return reject(new Error(error.message(response)));
48
+ }
49
+
50
+ return setTimeout(() => {
51
+ retry(response).then(resolve).catch(reject);
52
+ }, timeout());
53
+ }).catch(err => {
54
+ reject(err);
55
55
  });
56
56
  });
57
57
  };
@@ -332,7 +332,7 @@ function serializeUrl(host, path, queryParameters) {
332
332
  function serializeQueryParameters(parameters) {
333
333
  const isObjectOrArray = value => Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
334
334
 
335
- return Object.keys(parameters).map(key => `${key}=${isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]}`).join('&');
335
+ return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key])}`).join('&');
336
336
  }
337
337
  function serializeData(request, requestOptions) {
338
338
  if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
@@ -767,7 +767,7 @@ function createXhrRequester() {
767
767
  }
768
768
 
769
769
  // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
770
- const apiClientVersion = '5.0.0-alpha.2';
770
+ const apiClientVersion = '5.0.0-alpha.20';
771
771
  function getDefaultHosts(appId) {
772
772
  return [
773
773
  {
@@ -821,6 +821,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
821
821
  });
822
822
  return {
823
823
  transporter,
824
+ /**
825
+ * The `appId` currently in use.
826
+ */
827
+ appId: appIdOption,
828
+ /**
829
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
830
+ */
831
+ clearCache() {
832
+ return Promise.all([
833
+ transporter.requestsCache.clear(),
834
+ transporter.responsesCache.clear(),
835
+ ]).then(() => undefined);
836
+ },
824
837
  /**
825
838
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
826
839
  */
@@ -837,38 +850,57 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
837
850
  transporter.algoliaAgent.add({ segment, version });
838
851
  },
839
852
  /**
840
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
853
+ * Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
841
854
  *
842
- * @summary Wait for a task to complete.
855
+ * @summary Helper method that waits for a task to be published (completed).
843
856
  * @param waitForTaskOptions - The waitForTaskOptions object.
844
857
  * @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
845
858
  * @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
859
+ * @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
860
+ * @param waitForTaskOptions.timeout - The function to decide how long to wait between retries.
846
861
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
847
862
  */
848
- waitForTask({ indexName, taskID, ...createRetryablePromiseOptions }, requestOptions) {
849
- return createRetryablePromise({
850
- ...createRetryablePromiseOptions,
863
+ waitForTask({ indexName, taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
864
+ let retryCount = 0;
865
+ return createIterablePromise({
851
866
  func: () => this.getTask({ indexName, taskID }, requestOptions),
852
867
  validate: (response) => response.status === 'published',
868
+ aggregator: () => (retryCount += 1),
869
+ error: {
870
+ validate: () => retryCount >= maxRetries,
871
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
872
+ },
873
+ timeout: () => timeout(retryCount),
853
874
  });
854
875
  },
855
876
  /**
856
877
  * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
857
878
  *
858
- * @summary Wait for an API key task to be processed.
879
+ * @summary Helper method that waits for an API key task to be processed.
859
880
  * @param waitForApiKeyOptions - The waitForApiKeyOptions object.
860
881
  * @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
861
882
  * @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
862
883
  * @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
884
+ * @param waitForApiKeyOptions.maxRetries - The maximum number of retries. 50 by default.
885
+ * @param waitForApiKeyOptions.timeout - The function to decide how long to wait between retries.
863
886
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
864
887
  */
865
- waitForApiKey({ operation, key, apiKey, ...createRetryablePromiseOptions }, requestOptions) {
888
+ waitForApiKey({ operation, key, apiKey, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
889
+ let retryCount = 0;
890
+ const baseIteratorOptions = {
891
+ aggregator: () => (retryCount += 1),
892
+ error: {
893
+ validate: () => retryCount >= maxRetries,
894
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
895
+ },
896
+ timeout: () => timeout(retryCount),
897
+ };
866
898
  if (operation === 'update') {
867
899
  if (!apiKey) {
868
900
  throw new Error('`apiKey` is required when waiting for an `update` operation.');
869
901
  }
870
- return createRetryablePromise({
871
- ...createRetryablePromiseOptions,
902
+ return createIterablePromise({
903
+ ...baseIteratorOptions,
872
904
  func: () => this.getApiKey({ key }, requestOptions),
873
905
  validate: (response) => {
874
906
  for (const field of Object.keys(apiKey)) {
@@ -886,12 +918,99 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
886
918
  },
887
919
  });
888
920
  }
889
- return createRetryablePromise({
890
- ...createRetryablePromiseOptions,
921
+ return createIterablePromise({
922
+ ...baseIteratorOptions,
891
923
  func: () => this.getApiKey({ key }, requestOptions).catch((error) => error),
892
924
  validate: (error) => operation === 'add' ? error.status !== 404 : error.status === 404,
893
925
  });
894
926
  },
927
+ /**
928
+ * Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
929
+ *
930
+ * @summary Helper method that iterates on the `browse` method.
931
+ * @param browseObjects - The browseObjects object.
932
+ * @param browseObjects.indexName - The index in which to perform the request.
933
+ * @param browseObjects.browseParams - The `browse` parameters.
934
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is no `cursor` in the response.
935
+ * @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
936
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
937
+ */
938
+ browseObjects({ indexName, browseParams, ...browseObjectsOptions }, requestOptions) {
939
+ return createIterablePromise({
940
+ func: (previousResponse) => {
941
+ return this.browse({
942
+ indexName,
943
+ browseParams: {
944
+ cursor: previousResponse ? previousResponse.cursor : undefined,
945
+ ...browseParams,
946
+ },
947
+ }, requestOptions);
948
+ },
949
+ validate: (response) => response.cursor === undefined,
950
+ ...browseObjectsOptions,
951
+ });
952
+ },
953
+ /**
954
+ * Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
955
+ *
956
+ * @summary Helper method that iterates on the `searchRules` method.
957
+ * @param browseObjects - The browseObjects object.
958
+ * @param browseObjects.indexName - The index in which to perform the request.
959
+ * @param browseObjects.searchRulesParams - The `searchRules` method parameters.
960
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
961
+ * @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
962
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
963
+ */
964
+ browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
965
+ const params = {
966
+ hitsPerPage: 1000,
967
+ ...searchRulesParams,
968
+ };
969
+ return createIterablePromise({
970
+ func: (previousResponse) => {
971
+ return this.searchRules({
972
+ indexName,
973
+ searchRulesParams: {
974
+ ...params,
975
+ page: previousResponse
976
+ ? previousResponse.page + 1
977
+ : params.page || 0,
978
+ },
979
+ }, requestOptions);
980
+ },
981
+ validate: (response) => response.nbHits < params.hitsPerPage,
982
+ ...browseRulesOptions,
983
+ });
984
+ },
985
+ /**
986
+ * Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
987
+ *
988
+ * @summary Helper method that iterates on the `searchSynonyms` method.
989
+ * @param browseObjects - The browseObjects object.
990
+ * @param browseObjects.indexName - The index in which to perform the request.
991
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
992
+ * @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
993
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
994
+ */
995
+ browseSynonyms({ indexName, validate, aggregator, ...browseSynonymsOptions }, requestOptions) {
996
+ const params = {
997
+ hitsPerPage: 1000,
998
+ ...browseSynonymsOptions,
999
+ };
1000
+ return createIterablePromise({
1001
+ func: (previousResponse) => {
1002
+ return this.searchSynonyms({
1003
+ ...params,
1004
+ indexName,
1005
+ page: previousResponse
1006
+ ? previousResponse.page + 1
1007
+ : browseSynonymsOptions.page || 0,
1008
+ }, requestOptions);
1009
+ },
1010
+ validate: (response) => response.nbHits < params.hitsPerPage,
1011
+ ...browseSynonymsOptions,
1012
+ });
1013
+ },
895
1014
  /**
896
1015
  * Add a new API Key with specific permissions/restrictions.
897
1016
  *
@@ -1025,6 +1144,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1025
1144
  if (!batchWriteParams) {
1026
1145
  throw new Error('Parameter `batchWriteParams` is required when calling `batch`.');
1027
1146
  }
1147
+ if (!batchWriteParams.requests) {
1148
+ throw new Error('Parameter `batchWriteParams.requests` is required when calling `batch`.');
1149
+ }
1028
1150
  const requestPath = '/1/indexes/{indexName}/batch'.replace('{indexName}', encodeURIComponent(indexName));
1029
1151
  const headers = {};
1030
1152
  const queryParameters = {};
@@ -1111,10 +1233,10 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1111
1233
  * @summary Retrieve all index content.
1112
1234
  * @param browse - The browse object.
1113
1235
  * @param browse.indexName - The index in which to perform the request.
1114
- * @param browse.browseRequest - The browseRequest object.
1236
+ * @param browse.browseParams - The browseParams object.
1115
1237
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1116
1238
  */
1117
- browse({ indexName, browseRequest }, requestOptions) {
1239
+ browse({ indexName, browseParams }, requestOptions) {
1118
1240
  if (!indexName) {
1119
1241
  throw new Error('Parameter `indexName` is required when calling `browse`.');
1120
1242
  }
@@ -1126,7 +1248,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1126
1248
  path: requestPath,
1127
1249
  queryParameters,
1128
1250
  headers,
1129
- data: browseRequest ? browseRequest : {},
1251
+ data: browseParams ? browseParams : {},
1130
1252
  };
1131
1253
  return transporter.request(request, requestOptions);
1132
1254
  },
@@ -1260,15 +1382,15 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1260
1382
  * @summary Delete all records matching the query.
1261
1383
  * @param deleteBy - The deleteBy object.
1262
1384
  * @param deleteBy.indexName - The index in which to perform the request.
1263
- * @param deleteBy.searchParams - The searchParams object.
1385
+ * @param deleteBy.deleteByParams - The deleteByParams object.
1264
1386
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1265
1387
  */
1266
- deleteBy({ indexName, searchParams }, requestOptions) {
1388
+ deleteBy({ indexName, deleteByParams }, requestOptions) {
1267
1389
  if (!indexName) {
1268
1390
  throw new Error('Parameter `indexName` is required when calling `deleteBy`.');
1269
1391
  }
1270
- if (!searchParams) {
1271
- throw new Error('Parameter `searchParams` is required when calling `deleteBy`.');
1392
+ if (!deleteByParams) {
1393
+ throw new Error('Parameter `deleteByParams` is required when calling `deleteBy`.');
1272
1394
  }
1273
1395
  const requestPath = '/1/indexes/{indexName}/deleteByQuery'.replace('{indexName}', encodeURIComponent(indexName));
1274
1396
  const headers = {};
@@ -1278,7 +1400,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1278
1400
  path: requestPath,
1279
1401
  queryParameters,
1280
1402
  headers,
1281
- data: searchParams,
1403
+ data: deleteByParams,
1282
1404
  };
1283
1405
  return transporter.request(request, requestOptions);
1284
1406
  },
@@ -1517,7 +1639,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1517
1639
  * @param getLogs.type - Type of log entries to retrieve. When omitted, all log entries are retrieved.
1518
1640
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1519
1641
  */
1520
- getLogs({ offset, length, indexName, type }, requestOptions) {
1642
+ getLogs({ offset, length, indexName, type } = {}, requestOptions = undefined) {
1521
1643
  const requestPath = '/1/logs';
1522
1644
  const headers = {};
1523
1645
  const queryParameters = {};
@@ -1585,6 +1707,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1585
1707
  if (!getObjectsParams) {
1586
1708
  throw new Error('Parameter `getObjectsParams` is required when calling `getObjects`.');
1587
1709
  }
1710
+ if (!getObjectsParams.requests) {
1711
+ throw new Error('Parameter `getObjectsParams.requests` is required when calling `getObjects`.');
1712
+ }
1588
1713
  const requestPath = '/1/indexes/*/objects';
1589
1714
  const headers = {};
1590
1715
  const queryParameters = {};
@@ -1776,7 +1901,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1776
1901
  * @param hasPendingMappings.getClusters - If the clusters pending mapping state should be on the response.
1777
1902
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1778
1903
  */
1779
- hasPendingMappings({ getClusters }, requestOptions) {
1904
+ hasPendingMappings({ getClusters } = {}, requestOptions = undefined) {
1780
1905
  const requestPath = '/1/clusters/mapping/pending';
1781
1906
  const headers = {};
1782
1907
  const queryParameters = {};
@@ -1835,7 +1960,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1835
1960
  * @param listIndices.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination).
1836
1961
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1837
1962
  */
1838
- listIndices({ page }, requestOptions) {
1963
+ listIndices({ page } = {}, requestOptions = undefined) {
1839
1964
  const requestPath = '/1/indexes';
1840
1965
  const headers = {};
1841
1966
  const queryParameters = {};
@@ -1859,7 +1984,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1859
1984
  * @param listUserIds.hitsPerPage - Maximum number of objects to retrieve.
1860
1985
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1861
1986
  */
1862
- listUserIds({ page, hitsPerPage }, requestOptions) {
1987
+ listUserIds({ page, hitsPerPage } = {}, requestOptions = undefined) {
1863
1988
  const requestPath = '/1/clusters/mapping';
1864
1989
  const headers = {};
1865
1990
  const queryParameters = {};
@@ -1888,6 +2013,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1888
2013
  if (!batchParams) {
1889
2014
  throw new Error('Parameter `batchParams` is required when calling `multipleBatch`.');
1890
2015
  }
2016
+ if (!batchParams.requests) {
2017
+ throw new Error('Parameter `batchParams.requests` is required when calling `multipleBatch`.');
2018
+ }
1891
2019
  const requestPath = '/1/indexes/*/batch';
1892
2020
  const headers = {};
1893
2021
  const queryParameters = {};
@@ -1941,19 +2069,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1941
2069
  * @param partialUpdateObject - The partialUpdateObject object.
1942
2070
  * @param partialUpdateObject.indexName - The index in which to perform the request.
1943
2071
  * @param partialUpdateObject.objectID - Unique identifier of an object.
1944
- * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update.
2072
+ * @param partialUpdateObject.attributesToUpdate - Map of attribute(s) to update.
1945
2073
  * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet.
1946
2074
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1947
2075
  */
1948
- partialUpdateObject({ indexName, objectID, attributeOrBuiltInOperation, createIfNotExists, }, requestOptions) {
2076
+ partialUpdateObject({ indexName, objectID, attributesToUpdate, createIfNotExists, }, requestOptions) {
1949
2077
  if (!indexName) {
1950
2078
  throw new Error('Parameter `indexName` is required when calling `partialUpdateObject`.');
1951
2079
  }
1952
2080
  if (!objectID) {
1953
2081
  throw new Error('Parameter `objectID` is required when calling `partialUpdateObject`.');
1954
2082
  }
1955
- if (!attributeOrBuiltInOperation) {
1956
- throw new Error('Parameter `attributeOrBuiltInOperation` is required when calling `partialUpdateObject`.');
2083
+ if (!attributesToUpdate) {
2084
+ throw new Error('Parameter `attributesToUpdate` is required when calling `partialUpdateObject`.');
1957
2085
  }
1958
2086
  const requestPath = '/1/indexes/{indexName}/{objectID}/partial'
1959
2087
  .replace('{indexName}', encodeURIComponent(indexName))
@@ -1968,7 +2096,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1968
2096
  path: requestPath,
1969
2097
  queryParameters,
1970
2098
  headers,
1971
- data: attributeOrBuiltInOperation,
2099
+ data: attributesToUpdate,
1972
2100
  };
1973
2101
  return transporter.request(request, requestOptions);
1974
2102
  },
@@ -2169,17 +2297,17 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2169
2297
  * @summary Save a batch of rules.
2170
2298
  * @param saveRules - The saveRules object.
2171
2299
  * @param saveRules.indexName - The index in which to perform the request.
2172
- * @param saveRules.rule - The rule object.
2300
+ * @param saveRules.rules - The rules object.
2173
2301
  * @param saveRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName.
2174
2302
  * @param saveRules.clearExistingRules - When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept.
2175
2303
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
2176
2304
  */
2177
- saveRules({ indexName, rule, forwardToReplicas, clearExistingRules, }, requestOptions) {
2305
+ saveRules({ indexName, rules, forwardToReplicas, clearExistingRules, }, requestOptions) {
2178
2306
  if (!indexName) {
2179
2307
  throw new Error('Parameter `indexName` is required when calling `saveRules`.');
2180
2308
  }
2181
- if (!rule) {
2182
- throw new Error('Parameter `rule` is required when calling `saveRules`.');
2309
+ if (!rules) {
2310
+ throw new Error('Parameter `rules` is required when calling `saveRules`.');
2183
2311
  }
2184
2312
  const requestPath = '/1/indexes/{indexName}/rules/batch'.replace('{indexName}', encodeURIComponent(indexName));
2185
2313
  const headers = {};
@@ -2195,7 +2323,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2195
2323
  path: requestPath,
2196
2324
  queryParameters,
2197
2325
  headers,
2198
- data: rule,
2326
+ data: rules,
2199
2327
  };
2200
2328
  return transporter.request(request, requestOptions);
2201
2329
  },
@@ -2406,9 +2534,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2406
2534
  if (!indexName) {
2407
2535
  throw new Error('Parameter `indexName` is required when calling `searchRules`.');
2408
2536
  }
2409
- if (!searchRulesParams) {
2410
- throw new Error('Parameter `searchRulesParams` is required when calling `searchRules`.');
2411
- }
2412
2537
  const requestPath = '/1/indexes/{indexName}/rules/search'.replace('{indexName}', encodeURIComponent(indexName));
2413
2538
  const headers = {};
2414
2539
  const queryParameters = {};
@@ -2417,7 +2542,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2417
2542
  path: requestPath,
2418
2543
  queryParameters,
2419
2544
  headers,
2420
- data: searchRulesParams,
2545
+ data: searchRulesParams ? searchRulesParams : {},
2421
2546
  useReadTransporter: true,
2422
2547
  cacheable: true,
2423
2548
  };