@algolia/client-search 5.0.0-alpha.1 → 5.0.0-alpha.4

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 (215) 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 +144 -25
  6. package/dist/client-search.esm.browser.js +172 -53
  7. package/dist/client-search.esm.node.js +145 -26
  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/addApiKeyResponse.d.ts +1 -1
  12. package/dist/model/addApiKeyResponse.d.ts.map +1 -1
  13. package/dist/model/apiKey.d.ts.map +1 -1
  14. package/dist/model/attributeToUpdate.d.ts +3 -0
  15. package/dist/model/attributeToUpdate.d.ts.map +1 -0
  16. package/dist/model/automaticFacetFilter.d.ts.map +1 -1
  17. package/dist/model/baseGetApiKeyResponse.d.ts +11 -0
  18. package/dist/model/baseGetApiKeyResponse.d.ts.map +1 -0
  19. package/dist/model/baseIndexSettings.d.ts.map +1 -1
  20. package/dist/model/baseSearchParamsWithoutQuery.d.ts.map +1 -1
  21. package/dist/model/baseSearchResponse.d.ts +2 -2
  22. package/dist/model/baseSearchResponse.d.ts.map +1 -1
  23. package/dist/model/batchAssignUserIdsParams.d.ts.map +1 -1
  24. package/dist/model/batchDictionaryEntriesParams.d.ts.map +1 -1
  25. package/dist/model/batchDictionaryEntriesRequest.d.ts.map +1 -1
  26. package/dist/model/batchParams.d.ts +2 -2
  27. package/dist/model/batchParams.d.ts.map +1 -1
  28. package/dist/model/{batchOperation.d.ts → batchRequest.d.ts} +2 -2
  29. package/dist/model/batchRequest.d.ts.map +1 -0
  30. package/dist/model/batchResponse.d.ts.map +1 -1
  31. package/dist/model/batchWriteParams.d.ts +2 -2
  32. package/dist/model/batchWriteParams.d.ts.map +1 -1
  33. package/dist/model/browseRequest.d.ts.map +1 -1
  34. package/dist/model/browseResponse.d.ts +1 -1
  35. package/dist/model/browseResponse.d.ts.map +1 -1
  36. package/dist/model/builtInOperation.d.ts.map +1 -1
  37. package/dist/model/clientMethodProps.d.ts +21 -8
  38. package/dist/model/clientMethodProps.d.ts.map +1 -1
  39. package/dist/model/condition.d.ts.map +1 -1
  40. package/dist/model/consequence.d.ts.map +1 -1
  41. package/dist/model/consequenceQueryObject.d.ts.map +1 -1
  42. package/dist/model/deletedAtResponse.d.ts.map +1 -1
  43. package/dist/model/dictionaryEntry.d.ts.map +1 -1
  44. package/dist/model/distinct.d.ts +5 -0
  45. package/dist/model/distinct.d.ts.map +1 -0
  46. package/dist/model/edit.d.ts.map +1 -1
  47. package/dist/model/facetHits.d.ts.map +1 -1
  48. package/dist/model/facetOrdering.d.ts.map +1 -1
  49. package/dist/model/facetsStats.d.ts.map +1 -1
  50. package/dist/model/fetchedIndex.d.ts.map +1 -1
  51. package/dist/model/getApiKeyResponse.d.ts +4 -0
  52. package/dist/model/getApiKeyResponse.d.ts.map +1 -0
  53. package/dist/model/getObjectsParams.d.ts +2 -2
  54. package/dist/model/getObjectsParams.d.ts.map +1 -1
  55. package/dist/model/{multipleGetObjectsParams.d.ts → getObjectsRequest.d.ts} +2 -2
  56. package/dist/model/getObjectsRequest.d.ts.map +1 -0
  57. package/dist/model/getObjectsResponse.d.ts +2 -2
  58. package/dist/model/getObjectsResponse.d.ts.map +1 -1
  59. package/dist/model/hasPendingMappingsResponse.d.ts.map +1 -1
  60. package/dist/model/highlightResultOption.d.ts.map +1 -1
  61. package/dist/model/hit.d.ts +1 -1
  62. package/dist/model/hit.d.ts.map +1 -1
  63. package/dist/model/index.d.ts +7 -6
  64. package/dist/model/index.d.ts.map +1 -1
  65. package/dist/model/indexSettingsAsSearchParams.d.ts +2 -4
  66. package/dist/model/indexSettingsAsSearchParams.d.ts.map +1 -1
  67. package/dist/model/languages.d.ts.map +1 -1
  68. package/dist/model/listApiKeysResponse.d.ts +2 -2
  69. package/dist/model/listApiKeysResponse.d.ts.map +1 -1
  70. package/dist/model/listIndicesResponse.d.ts +1 -1
  71. package/dist/model/listIndicesResponse.d.ts.map +1 -1
  72. package/dist/model/log.d.ts.map +1 -1
  73. package/dist/model/logQuery.d.ts.map +1 -1
  74. package/dist/model/matchedGeoLocation.d.ts.map +1 -1
  75. package/dist/model/{multipleBatchOperation.d.ts → multipleBatchRequest.d.ts} +5 -5
  76. package/dist/model/multipleBatchRequest.d.ts.map +1 -0
  77. package/dist/model/multipleBatchResponse.d.ts +2 -2
  78. package/dist/model/multipleBatchResponse.d.ts.map +1 -1
  79. package/dist/model/operationIndexParams.d.ts.map +1 -1
  80. package/dist/model/params.d.ts.map +1 -1
  81. package/dist/model/personalization.d.ts.map +1 -1
  82. package/dist/model/promoteObjectID.d.ts.map +1 -1
  83. package/dist/model/promoteObjectIDs.d.ts.map +1 -1
  84. package/dist/model/rankingInfo.d.ts.map +1 -1
  85. package/dist/model/rule.d.ts.map +1 -1
  86. package/dist/model/saveObjectResponse.d.ts +2 -2
  87. package/dist/model/saveObjectResponse.d.ts.map +1 -1
  88. package/dist/model/saveSynonymResponse.d.ts.map +1 -1
  89. package/dist/model/searchDictionaryEntriesParams.d.ts.map +1 -1
  90. package/dist/model/searchForFacetValuesRequest.d.ts.map +1 -1
  91. package/dist/model/searchForFacetsOptions.d.ts.map +1 -1
  92. package/dist/model/searchForHitsOptions.d.ts.map +1 -1
  93. package/dist/model/searchHits.d.ts +2 -2
  94. package/dist/model/searchHits.d.ts.map +1 -1
  95. package/dist/model/searchMethodParams.d.ts.map +1 -1
  96. package/dist/model/searchResponse.d.ts +1 -1
  97. package/dist/model/searchResponse.d.ts.map +1 -1
  98. package/dist/model/searchResponses.d.ts +1 -1
  99. package/dist/model/searchResponses.d.ts.map +1 -1
  100. package/dist/model/searchRulesParams.d.ts.map +1 -1
  101. package/dist/model/searchRulesResponse.d.ts.map +1 -1
  102. package/dist/model/searchSynonymsResponse.d.ts.map +1 -1
  103. package/dist/model/searchUserIdsParams.d.ts.map +1 -1
  104. package/dist/model/searchUserIdsResponse.d.ts.map +1 -1
  105. package/dist/model/snippetResultOption.d.ts.map +1 -1
  106. package/dist/model/source.d.ts.map +1 -1
  107. package/dist/model/standardEntries.d.ts.map +1 -1
  108. package/dist/model/synonymHit.d.ts.map +1 -1
  109. package/dist/model/synonymHitHighlightResult.d.ts.map +1 -1
  110. package/dist/model/timeRange.d.ts.map +1 -1
  111. package/dist/model/updateApiKeyResponse.d.ts +1 -1
  112. package/dist/model/updateApiKeyResponse.d.ts.map +1 -1
  113. package/dist/model/updatedAtResponse.d.ts.map +1 -1
  114. package/dist/model/updatedAtWithObjectIdResponse.d.ts.map +1 -1
  115. package/dist/model/updatedRuleResponse.d.ts.map +1 -1
  116. package/dist/model/userHighlightResult.d.ts.map +1 -1
  117. package/dist/model/userHit.d.ts.map +1 -1
  118. package/dist/model/userId.d.ts.map +1 -1
  119. package/dist/model/value.d.ts.map +1 -1
  120. package/dist/src/searchClient.d.ts +65 -15
  121. package/dist/src/searchClient.d.ts.map +1 -1
  122. package/model/acl.ts +3 -0
  123. package/model/addApiKeyResponse.ts +2 -1
  124. package/model/apiKey.ts +7 -0
  125. package/model/{attributeOrBuiltInOperation.ts → attributeToUpdate.ts} +1 -1
  126. package/model/automaticFacetFilter.ts +2 -0
  127. package/model/baseGetApiKeyResponse.ts +13 -0
  128. package/model/baseIndexSettings.ts +13 -0
  129. package/model/baseSearchParamsWithoutQuery.ts +32 -0
  130. package/model/baseSearchResponse.ts +26 -2
  131. package/model/batchAssignUserIdsParams.ts +1 -0
  132. package/model/batchDictionaryEntriesParams.ts +1 -0
  133. package/model/batchDictionaryEntriesRequest.ts +1 -0
  134. package/model/batchParams.ts +2 -2
  135. package/model/{batchOperation.ts → batchRequest.ts} +2 -1
  136. package/model/batchResponse.ts +1 -0
  137. package/model/batchWriteParams.ts +2 -2
  138. package/model/browseRequest.ts +1 -0
  139. package/model/browseResponse.ts +1 -1
  140. package/model/builtInOperation.ts +1 -0
  141. package/model/clientMethodProps.ts +28 -12
  142. package/model/condition.ts +3 -0
  143. package/model/consequence.ts +4 -0
  144. package/model/consequenceQueryObject.ts +1 -0
  145. package/model/deletedAtResponse.ts +1 -0
  146. package/model/dictionaryEntry.ts +5 -0
  147. package/model/{createdAtObject.ts → distinct.ts} +4 -6
  148. package/model/edit.ts +2 -0
  149. package/model/facetHits.ts +2 -0
  150. package/model/facetOrdering.ts +1 -0
  151. package/model/facetsStats.ts +3 -0
  152. package/model/fetchedIndex.ts +10 -0
  153. package/model/{key.ts → getApiKeyResponse.ts} +2 -2
  154. package/model/getObjectsParams.ts +2 -2
  155. package/model/{multipleGetObjectsParams.ts → getObjectsRequest.ts} +3 -1
  156. package/model/getObjectsResponse.ts +2 -2
  157. package/model/hasPendingMappingsResponse.ts +1 -0
  158. package/model/highlightResultOption.ts +3 -0
  159. package/model/hit.ts +5 -1
  160. package/model/index.ts +7 -6
  161. package/model/indexSettingsAsSearchParams.ts +43 -4
  162. package/model/languages.ts +2 -0
  163. package/model/listApiKeysResponse.ts +2 -2
  164. package/model/listIndicesResponse.ts +2 -1
  165. package/model/log.ts +14 -0
  166. package/model/logQuery.ts +2 -0
  167. package/model/matchedGeoLocation.ts +2 -0
  168. package/model/{multipleBatchOperation.ts → multipleBatchRequest.ts} +6 -4
  169. package/model/multipleBatchResponse.ts +3 -2
  170. package/model/operationIndexParams.ts +2 -0
  171. package/model/params.ts +3 -0
  172. package/model/personalization.ts +2 -0
  173. package/model/promoteObjectID.ts +1 -0
  174. package/model/promoteObjectIDs.ts +1 -0
  175. package/model/rankingInfo.ts +12 -0
  176. package/model/rule.ts +5 -0
  177. package/model/saveObjectResponse.ts +4 -2
  178. package/model/saveSynonymResponse.ts +2 -0
  179. package/model/searchDictionaryEntriesParams.ts +3 -0
  180. package/model/searchForFacetValuesRequest.ts +2 -0
  181. package/model/searchForFacetsOptions.ts +4 -0
  182. package/model/searchForHitsOptions.ts +1 -0
  183. package/model/searchHits.ts +2 -2
  184. package/model/searchMethodParams.ts +1 -0
  185. package/model/searchResponse.ts +2 -1
  186. package/model/searchResponses.ts +1 -1
  187. package/model/searchRulesParams.ts +6 -0
  188. package/model/searchRulesResponse.ts +3 -0
  189. package/model/searchSynonymsResponse.ts +1 -0
  190. package/model/searchUserIdsParams.ts +3 -0
  191. package/model/searchUserIdsResponse.ts +4 -0
  192. package/model/snippetResultOption.ts +1 -0
  193. package/model/source.ts +1 -0
  194. package/model/standardEntries.ts +2 -0
  195. package/model/synonymHit.ts +8 -0
  196. package/model/synonymHitHighlightResult.ts +1 -0
  197. package/model/timeRange.ts +1 -0
  198. package/model/updateApiKeyResponse.ts +2 -1
  199. package/model/updatedAtResponse.ts +1 -0
  200. package/model/updatedAtWithObjectIdResponse.ts +2 -0
  201. package/model/updatedRuleResponse.ts +2 -0
  202. package/model/userHighlightResult.ts +1 -0
  203. package/model/userHit.ts +5 -0
  204. package/model/userId.ts +3 -0
  205. package/model/value.ts +1 -0
  206. package/package.json +5 -5
  207. package/dist/model/attributeOrBuiltInOperation.d.ts +0 -3
  208. package/dist/model/attributeOrBuiltInOperation.d.ts.map +0 -1
  209. package/dist/model/batchOperation.d.ts.map +0 -1
  210. package/dist/model/createdAtObject.d.ts +0 -7
  211. package/dist/model/createdAtObject.d.ts.map +0 -1
  212. package/dist/model/key.d.ts +0 -4
  213. package/dist/model/key.d.ts.map +0 -1
  214. package/dist/model/multipleBatchOperation.d.ts.map +0 -1
  215. package/dist/model/multipleGetObjectsParams.d.ts.map +0 -1
@@ -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
  };
@@ -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.1';
770
+ const apiClientVersion = '5.0.0-alpha.4';
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.browseRequest - The `browse` method parameters.
934
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
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, browseRequest, ...browseObjectsOptions }, requestOptions) {
939
+ return createIterablePromise({
940
+ func: (previousResponse) => {
941
+ return this.browse({
942
+ indexName,
943
+ browseRequest: {
944
+ cursor: previousResponse ? previousResponse.cursor : undefined,
945
+ ...browseRequest,
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.
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.
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
  *
@@ -1585,6 +1704,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1585
1704
  if (!getObjectsParams) {
1586
1705
  throw new Error('Parameter `getObjectsParams` is required when calling `getObjects`.');
1587
1706
  }
1707
+ if (!getObjectsParams.requests) {
1708
+ throw new Error('Parameter `getObjectsParams.requests` is required when calling `getObjects`.');
1709
+ }
1588
1710
  const requestPath = '/1/indexes/*/objects';
1589
1711
  const headers = {};
1590
1712
  const queryParameters = {};
@@ -1888,6 +2010,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1888
2010
  if (!batchParams) {
1889
2011
  throw new Error('Parameter `batchParams` is required when calling `multipleBatch`.');
1890
2012
  }
2013
+ if (!batchParams.requests) {
2014
+ throw new Error('Parameter `batchParams.requests` is required when calling `multipleBatch`.');
2015
+ }
1891
2016
  const requestPath = '/1/indexes/*/batch';
1892
2017
  const headers = {};
1893
2018
  const queryParameters = {};
@@ -1941,19 +2066,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1941
2066
  * @param partialUpdateObject - The partialUpdateObject object.
1942
2067
  * @param partialUpdateObject.indexName - The index in which to perform the request.
1943
2068
  * @param partialUpdateObject.objectID - Unique identifier of an object.
1944
- * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update.
2069
+ * @param partialUpdateObject.attributeToUpdate - List of attributes to update.
1945
2070
  * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet.
1946
2071
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1947
2072
  */
1948
- partialUpdateObject({ indexName, objectID, attributeOrBuiltInOperation, createIfNotExists, }, requestOptions) {
2073
+ partialUpdateObject({ indexName, objectID, attributeToUpdate, createIfNotExists, }, requestOptions) {
1949
2074
  if (!indexName) {
1950
2075
  throw new Error('Parameter `indexName` is required when calling `partialUpdateObject`.');
1951
2076
  }
1952
2077
  if (!objectID) {
1953
2078
  throw new Error('Parameter `objectID` is required when calling `partialUpdateObject`.');
1954
2079
  }
1955
- if (!attributeOrBuiltInOperation) {
1956
- throw new Error('Parameter `attributeOrBuiltInOperation` is required when calling `partialUpdateObject`.');
2080
+ if (!attributeToUpdate) {
2081
+ throw new Error('Parameter `attributeToUpdate` is required when calling `partialUpdateObject`.');
1957
2082
  }
1958
2083
  const requestPath = '/1/indexes/{indexName}/{objectID}/partial'
1959
2084
  .replace('{indexName}', encodeURIComponent(indexName))
@@ -1968,7 +2093,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1968
2093
  path: requestPath,
1969
2094
  queryParameters,
1970
2095
  headers,
1971
- data: attributeOrBuiltInOperation,
2096
+ data: attributeToUpdate,
1972
2097
  };
1973
2098
  return transporter.request(request, requestOptions);
1974
2099
  },
@@ -2406,9 +2531,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2406
2531
  if (!indexName) {
2407
2532
  throw new Error('Parameter `indexName` is required when calling `searchRules`.');
2408
2533
  }
2409
- if (!searchRulesParams) {
2410
- throw new Error('Parameter `searchRulesParams` is required when calling `searchRules`.');
2411
- }
2412
2534
  const requestPath = '/1/indexes/{indexName}/rules/search'.replace('{indexName}', encodeURIComponent(indexName));
2413
2535
  const headers = {};
2414
2536
  const queryParameters = {};
@@ -2417,7 +2539,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2417
2539
  path: requestPath,
2418
2540
  queryParameters,
2419
2541
  headers,
2420
- data: searchRulesParams,
2542
+ data: searchRulesParams ? searchRulesParams : {},
2421
2543
  useReadTransporter: true,
2422
2544
  cacheable: true,
2423
2545
  };
@@ -2436,9 +2558,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2436
2558
  if (!indexName) {
2437
2559
  throw new Error('Parameter `indexName` is required when calling `searchSingleIndex`.');
2438
2560
  }
2439
- if (!searchParams) {
2440
- throw new Error('Parameter `searchParams` is required when calling `searchSingleIndex`.');
2441
- }
2442
2561
  const requestPath = '/1/indexes/{indexName}/query'.replace('{indexName}', encodeURIComponent(indexName));
2443
2562
  const headers = {};
2444
2563
  const queryParameters = {};
@@ -2447,7 +2566,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2447
2566
  path: requestPath,
2448
2567
  queryParameters,
2449
2568
  headers,
2450
- data: searchParams,
2569
+ data: searchParams ? searchParams : {},
2451
2570
  useReadTransporter: true,
2452
2571
  cacheable: true,
2453
2572
  };
@@ -1,8 +1,8 @@
1
- import { createAuth, createTransporter, getAlgoliaAgent, createRetryablePromise, shuffle, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE, createNullCache, createMemoryCache } from '@algolia/client-common';
1
+ import { createAuth, createTransporter, getAlgoliaAgent, createIterablePromise, shuffle, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE, createNullCache, createMemoryCache } from '@algolia/client-common';
2
2
  import { createHttpRequester } from '@algolia/requester-node-http';
3
3
 
4
4
  // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
5
- const apiClientVersion = '5.0.0-alpha.1';
5
+ const apiClientVersion = '5.0.0-alpha.4';
6
6
  function getDefaultHosts(appId) {
7
7
  return [
8
8
  {
@@ -56,6 +56,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
56
56
  });
57
57
  return {
58
58
  transporter,
59
+ /**
60
+ * The `appId` currently in use.
61
+ */
62
+ appId: appIdOption,
63
+ /**
64
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
65
+ */
66
+ clearCache() {
67
+ return Promise.all([
68
+ transporter.requestsCache.clear(),
69
+ transporter.responsesCache.clear(),
70
+ ]).then(() => undefined);
71
+ },
59
72
  /**
60
73
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
61
74
  */
@@ -72,38 +85,57 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
72
85
  transporter.algoliaAgent.add({ segment, version });
73
86
  },
74
87
  /**
75
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
88
+ * Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
76
89
  *
77
- * @summary Wait for a task to complete.
90
+ * @summary Helper method that waits for a task to be published (completed).
78
91
  * @param waitForTaskOptions - The waitForTaskOptions object.
79
92
  * @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
80
93
  * @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
94
+ * @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
95
+ * @param waitForTaskOptions.timeout - The function to decide how long to wait between retries.
81
96
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
82
97
  */
83
- waitForTask({ indexName, taskID, ...createRetryablePromiseOptions }, requestOptions) {
84
- return createRetryablePromise({
85
- ...createRetryablePromiseOptions,
98
+ waitForTask({ indexName, taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
99
+ let retryCount = 0;
100
+ return createIterablePromise({
86
101
  func: () => this.getTask({ indexName, taskID }, requestOptions),
87
102
  validate: (response) => response.status === 'published',
103
+ aggregator: () => (retryCount += 1),
104
+ error: {
105
+ validate: () => retryCount >= maxRetries,
106
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
107
+ },
108
+ timeout: () => timeout(retryCount),
88
109
  });
89
110
  },
90
111
  /**
91
112
  * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
92
113
  *
93
- * @summary Wait for an API key task to be processed.
114
+ * @summary Helper method that waits for an API key task to be processed.
94
115
  * @param waitForApiKeyOptions - The waitForApiKeyOptions object.
95
116
  * @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
96
117
  * @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
97
118
  * @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
119
+ * @param waitForApiKeyOptions.maxRetries - The maximum number of retries. 50 by default.
120
+ * @param waitForApiKeyOptions.timeout - The function to decide how long to wait between retries.
98
121
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
99
122
  */
100
- waitForApiKey({ operation, key, apiKey, ...createRetryablePromiseOptions }, requestOptions) {
123
+ waitForApiKey({ operation, key, apiKey, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
124
+ let retryCount = 0;
125
+ const baseIteratorOptions = {
126
+ aggregator: () => (retryCount += 1),
127
+ error: {
128
+ validate: () => retryCount >= maxRetries,
129
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
130
+ },
131
+ timeout: () => timeout(retryCount),
132
+ };
101
133
  if (operation === 'update') {
102
134
  if (!apiKey) {
103
135
  throw new Error('`apiKey` is required when waiting for an `update` operation.');
104
136
  }
105
- return createRetryablePromise({
106
- ...createRetryablePromiseOptions,
137
+ return createIterablePromise({
138
+ ...baseIteratorOptions,
107
139
  func: () => this.getApiKey({ key }, requestOptions),
108
140
  validate: (response) => {
109
141
  for (const field of Object.keys(apiKey)) {
@@ -121,12 +153,99 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
121
153
  },
122
154
  });
123
155
  }
124
- return createRetryablePromise({
125
- ...createRetryablePromiseOptions,
156
+ return createIterablePromise({
157
+ ...baseIteratorOptions,
126
158
  func: () => this.getApiKey({ key }, requestOptions).catch((error) => error),
127
159
  validate: (error) => operation === 'add' ? error.status !== 404 : error.status === 404,
128
160
  });
129
161
  },
162
+ /**
163
+ * Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
164
+ *
165
+ * @summary Helper method that iterates on the `browse` method.
166
+ * @param browseObjects - The browseObjects object.
167
+ * @param browseObjects.indexName - The index in which to perform the request.
168
+ * @param browseObjects.browseRequest - The `browse` method parameters.
169
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
170
+ * @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`.
171
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
172
+ */
173
+ browseObjects({ indexName, browseRequest, ...browseObjectsOptions }, requestOptions) {
174
+ return createIterablePromise({
175
+ func: (previousResponse) => {
176
+ return this.browse({
177
+ indexName,
178
+ browseRequest: {
179
+ cursor: previousResponse ? previousResponse.cursor : undefined,
180
+ ...browseRequest,
181
+ },
182
+ }, requestOptions);
183
+ },
184
+ validate: (response) => response.cursor === undefined,
185
+ ...browseObjectsOptions,
186
+ });
187
+ },
188
+ /**
189
+ * Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
190
+ *
191
+ * @summary Helper method that iterates on the `searchRules` method.
192
+ * @param browseObjects - The browseObjects object.
193
+ * @param browseObjects.indexName - The index in which to perform the request.
194
+ * @param browseObjects.searchRulesParams - The `searchRules` method parameters.
195
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
196
+ * @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`.
197
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
198
+ */
199
+ browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
200
+ const params = {
201
+ hitsPerPage: 1000,
202
+ ...searchRulesParams,
203
+ };
204
+ return createIterablePromise({
205
+ func: (previousResponse) => {
206
+ return this.searchRules({
207
+ indexName,
208
+ searchRulesParams: {
209
+ ...params,
210
+ page: previousResponse
211
+ ? previousResponse.page + 1
212
+ : params.page || 0,
213
+ },
214
+ }, requestOptions);
215
+ },
216
+ validate: (response) => response.nbHits < params.hitsPerPage,
217
+ ...browseRulesOptions,
218
+ });
219
+ },
220
+ /**
221
+ * Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
222
+ *
223
+ * @summary Helper method that iterates on the `searchSynonyms` method.
224
+ * @param browseObjects - The browseObjects object.
225
+ * @param browseObjects.indexName - The index in which to perform the request.
226
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
227
+ * @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`.
228
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
229
+ */
230
+ browseSynonyms({ indexName, validate, aggregator, ...browseSynonymsOptions }, requestOptions) {
231
+ const params = {
232
+ hitsPerPage: 1000,
233
+ ...browseSynonymsOptions,
234
+ };
235
+ return createIterablePromise({
236
+ func: (previousResponse) => {
237
+ return this.searchSynonyms({
238
+ ...params,
239
+ indexName,
240
+ page: previousResponse
241
+ ? previousResponse.page + 1
242
+ : browseSynonymsOptions.page || 0,
243
+ }, requestOptions);
244
+ },
245
+ validate: (response) => response.nbHits < params.hitsPerPage,
246
+ ...browseSynonymsOptions,
247
+ });
248
+ },
130
249
  /**
131
250
  * Add a new API Key with specific permissions/restrictions.
132
251
  *
@@ -820,6 +939,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
820
939
  if (!getObjectsParams) {
821
940
  throw new Error('Parameter `getObjectsParams` is required when calling `getObjects`.');
822
941
  }
942
+ if (!getObjectsParams.requests) {
943
+ throw new Error('Parameter `getObjectsParams.requests` is required when calling `getObjects`.');
944
+ }
823
945
  const requestPath = '/1/indexes/*/objects';
824
946
  const headers = {};
825
947
  const queryParameters = {};
@@ -1123,6 +1245,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1123
1245
  if (!batchParams) {
1124
1246
  throw new Error('Parameter `batchParams` is required when calling `multipleBatch`.');
1125
1247
  }
1248
+ if (!batchParams.requests) {
1249
+ throw new Error('Parameter `batchParams.requests` is required when calling `multipleBatch`.');
1250
+ }
1126
1251
  const requestPath = '/1/indexes/*/batch';
1127
1252
  const headers = {};
1128
1253
  const queryParameters = {};
@@ -1176,19 +1301,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1176
1301
  * @param partialUpdateObject - The partialUpdateObject object.
1177
1302
  * @param partialUpdateObject.indexName - The index in which to perform the request.
1178
1303
  * @param partialUpdateObject.objectID - Unique identifier of an object.
1179
- * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update.
1304
+ * @param partialUpdateObject.attributeToUpdate - List of attributes to update.
1180
1305
  * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet.
1181
1306
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1182
1307
  */
1183
- partialUpdateObject({ indexName, objectID, attributeOrBuiltInOperation, createIfNotExists, }, requestOptions) {
1308
+ partialUpdateObject({ indexName, objectID, attributeToUpdate, createIfNotExists, }, requestOptions) {
1184
1309
  if (!indexName) {
1185
1310
  throw new Error('Parameter `indexName` is required when calling `partialUpdateObject`.');
1186
1311
  }
1187
1312
  if (!objectID) {
1188
1313
  throw new Error('Parameter `objectID` is required when calling `partialUpdateObject`.');
1189
1314
  }
1190
- if (!attributeOrBuiltInOperation) {
1191
- throw new Error('Parameter `attributeOrBuiltInOperation` is required when calling `partialUpdateObject`.');
1315
+ if (!attributeToUpdate) {
1316
+ throw new Error('Parameter `attributeToUpdate` is required when calling `partialUpdateObject`.');
1192
1317
  }
1193
1318
  const requestPath = '/1/indexes/{indexName}/{objectID}/partial'
1194
1319
  .replace('{indexName}', encodeURIComponent(indexName))
@@ -1203,7 +1328,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1203
1328
  path: requestPath,
1204
1329
  queryParameters,
1205
1330
  headers,
1206
- data: attributeOrBuiltInOperation,
1331
+ data: attributeToUpdate,
1207
1332
  };
1208
1333
  return transporter.request(request, requestOptions);
1209
1334
  },
@@ -1641,9 +1766,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1641
1766
  if (!indexName) {
1642
1767
  throw new Error('Parameter `indexName` is required when calling `searchRules`.');
1643
1768
  }
1644
- if (!searchRulesParams) {
1645
- throw new Error('Parameter `searchRulesParams` is required when calling `searchRules`.');
1646
- }
1647
1769
  const requestPath = '/1/indexes/{indexName}/rules/search'.replace('{indexName}', encodeURIComponent(indexName));
1648
1770
  const headers = {};
1649
1771
  const queryParameters = {};
@@ -1652,7 +1774,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1652
1774
  path: requestPath,
1653
1775
  queryParameters,
1654
1776
  headers,
1655
- data: searchRulesParams,
1777
+ data: searchRulesParams ? searchRulesParams : {},
1656
1778
  useReadTransporter: true,
1657
1779
  cacheable: true,
1658
1780
  };
@@ -1671,9 +1793,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1671
1793
  if (!indexName) {
1672
1794
  throw new Error('Parameter `indexName` is required when calling `searchSingleIndex`.');
1673
1795
  }
1674
- if (!searchParams) {
1675
- throw new Error('Parameter `searchParams` is required when calling `searchSingleIndex`.');
1676
- }
1677
1796
  const requestPath = '/1/indexes/{indexName}/query'.replace('{indexName}', encodeURIComponent(indexName));
1678
1797
  const headers = {};
1679
1798
  const queryParameters = {};
@@ -1682,7 +1801,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1682
1801
  path: requestPath,
1683
1802
  queryParameters,
1684
1803
  headers,
1685
- data: searchParams,
1804
+ data: searchParams ? searchParams : {},
1686
1805
  useReadTransporter: true,
1687
1806
  cacheable: true,
1688
1807
  };