Skip to content

Commit 53be992

Browse files
algolia-botFluf22millotp
committed
chore: generated code for commit a68907d. [skip ci]
Co-authored-by: Thomas Raffray <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent a68907d commit 53be992

File tree

25 files changed

+905
-110
lines changed

25 files changed

+905
-110
lines changed

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5801,8 +5801,8 @@ public void waitForAppTask(Long taskID) {
58015801
* the transporter requestOptions. (optional)
58025802
*/
58035803
public GetApiKeyResponse waitForApiKey(
5804-
ApiKeyOperation operation,
58055804
String key,
5805+
ApiKeyOperation operation,
58065806
ApiKey apiKey,
58075807
int maxRetries,
58085808
IntUnaryOperator timeout,
@@ -5835,28 +5835,26 @@ public GetApiKeyResponse waitForApiKey(
58355835
);
58365836
}
58375837

5838-
// bypass lambda restriction to modify final object
5839-
final GetApiKeyResponse[] addedKey = new GetApiKeyResponse[] { null };
5840-
5841-
// check the status of the getApiKey method
5842-
TaskUtils.retryUntil(
5838+
return TaskUtils.retryUntil(
58435839
() -> {
58445840
try {
5845-
addedKey[0] = this.getApiKey(key, requestOptions);
5846-
// magic number to signify we found the key
5847-
return -2;
5841+
return this.getApiKey(key, requestOptions);
58485842
} catch (AlgoliaApiException e) {
5849-
return e.getStatusCode();
5843+
if (e.getStatusCode() == 404) {
5844+
return null;
5845+
}
5846+
5847+
throw e;
58505848
}
58515849
},
5852-
(Integer status) -> {
5850+
(GetApiKeyResponse response) -> {
58535851
switch (operation) {
58545852
case ADD:
5855-
// stop either when the key is created or when we don't receive 404
5856-
return status == -2 || status != 404;
5853+
// stop when we don't receive 404 meaning the key is created
5854+
return response != null;
58575855
case DELETE:
58585856
// stop when the key is not found
5859-
return status == 404;
5857+
return response == null;
58605858
default:
58615859
// continue
58625860
return false;
@@ -5865,105 +5863,103 @@ public GetApiKeyResponse waitForApiKey(
58655863
maxRetries,
58665864
timeout
58675865
);
5868-
5869-
return addedKey[0];
58705866
}
58715867

58725868
/**
58735869
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
58745870
*
5875-
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
58765871
* @param key The `key` that has been added or deleted.
5872+
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
58775873
* @param maxRetries The maximum number of retry. 50 by default. (optional)
58785874
* @param timeout The function to decide how long to wait between retries. min(retries * 200,
58795875
* 5000) by default. (optional)
58805876
* @param requestOptions The requestOptions to send along with the query, they will be merged with
58815877
* the transporter requestOptions. (optional)
58825878
*/
58835879
public GetApiKeyResponse waitForApiKey(
5884-
ApiKeyOperation operation,
58855880
String key,
5881+
ApiKeyOperation operation,
58865882
int maxRetries,
58875883
IntUnaryOperator timeout,
58885884
RequestOptions requestOptions
58895885
) {
5890-
return this.waitForApiKey(operation, key, null, maxRetries, timeout, requestOptions);
5886+
return this.waitForApiKey(key, operation, null, maxRetries, timeout, requestOptions);
58915887
}
58925888

58935889
/**
58945890
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
58955891
*
5896-
* @param operation The `operation` that was done on a `key`.
58975892
* @param key The `key` that has been added, deleted or updated.
5893+
* @param operation The `operation` that was done on a `key`.
58985894
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
58995895
* the response with it.
59005896
* @param requestOptions The requestOptions to send along with the query, they will be merged with
59015897
* the transporter requestOptions. (optional)
59025898
*/
5903-
public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, ApiKey apiKey, RequestOptions requestOptions) {
5904-
return this.waitForApiKey(operation, key, apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
5899+
public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation, ApiKey apiKey, RequestOptions requestOptions) {
5900+
return this.waitForApiKey(key, operation, apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
59055901
}
59065902

59075903
/**
59085904
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
59095905
*
5910-
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
59115906
* @param key The `key` that has been added or deleted.
5907+
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
59125908
* @param requestOptions The requestOptions to send along with the query, they will be merged with
59135909
* the transporter requestOptions. (optional)
59145910
*/
5915-
public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, RequestOptions requestOptions) {
5916-
return this.waitForApiKey(operation, key, null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
5911+
public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation, RequestOptions requestOptions) {
5912+
return this.waitForApiKey(key, operation, null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, requestOptions);
59175913
}
59185914

59195915
/**
59205916
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
59215917
*
5922-
* @param operation The `operation` that was done on a `key`.
59235918
* @param key The `key` that has been added, deleted or updated.
5919+
* @param operation The `operation` that was done on a `key`.
59245920
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
59255921
* the response with it.
59265922
* @param maxRetries The maximum number of retry. 50 by default. (optional)
59275923
* @param timeout The function to decide how long to wait between retries. min(retries * 200,
59285924
* 5000) by default. (optional)
59295925
*/
5930-
public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, ApiKey apiKey, int maxRetries, IntUnaryOperator timeout) {
5931-
return this.waitForApiKey(operation, key, apiKey, maxRetries, timeout, null);
5926+
public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation, ApiKey apiKey, int maxRetries, IntUnaryOperator timeout) {
5927+
return this.waitForApiKey(key, operation, apiKey, maxRetries, timeout, null);
59325928
}
59335929

59345930
/**
59355931
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
59365932
*
5937-
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
59385933
* @param key The `key` that has been added or deleted.
5934+
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
59395935
* @param maxRetries The maximum number of retry. 50 by default. (optional)
59405936
* @param timeout The function to decide how long to wait between retries. min(retries * 200,
59415937
* 5000) by default. (optional)
59425938
*/
5943-
public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, int maxRetries, IntUnaryOperator timeout) {
5944-
return this.waitForApiKey(operation, key, null, maxRetries, timeout, null);
5939+
public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation, int maxRetries, IntUnaryOperator timeout) {
5940+
return this.waitForApiKey(key, operation, null, maxRetries, timeout, null);
59455941
}
59465942

59475943
/**
59485944
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
59495945
*
5950-
* @param operation The `operation` that was done on a `key`.
59515946
* @param key The `key` that has been added, deleted or updated.
5947+
* @param operation The `operation` that was done on a `key`.
59525948
* @param apiKey Necessary to know if an `update` operation has been processed, compare fields of
59535949
* the response with it.
59545950
*/
5955-
public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key, ApiKey apiKey) {
5956-
return this.waitForApiKey(operation, key, apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
5951+
public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation, ApiKey apiKey) {
5952+
return this.waitForApiKey(key, operation, apiKey, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
59575953
}
59585954

59595955
/**
59605956
* Helper: Wait for an API key to be added or deleted based on a given `operation`.
59615957
*
5962-
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
59635958
* @param key The `key` that has been added or deleted.
5959+
* @param operation The `operation` that was done on a `key`. (ADD or DELETE only)
59645960
*/
5965-
public GetApiKeyResponse waitForApiKey(ApiKeyOperation operation, String key) {
5966-
return this.waitForApiKey(operation, key, null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
5961+
public GetApiKeyResponse waitForApiKey(String key, ApiKeyOperation operation) {
5962+
return this.waitForApiKey(key, operation, null, TaskUtils.DEFAULT_MAX_RETRIES, TaskUtils.DEFAULT_TIMEOUT, null);
59675963
}
59685964

59695965
/**

clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,19 @@ export function createSearchClient({
320320
Math.min(retryCount * 200, 5000),
321321
}: WaitForApiKeyOptions,
322322
requestOptions?: RequestOptions
323-
): Promise<ApiError | GetApiKeyResponse> {
323+
): Promise<GetApiKeyResponse | undefined> {
324324
let retryCount = 0;
325-
const baseIteratorOptions: IterableOptions<ApiError | GetApiKeyResponse> =
326-
{
327-
aggregator: () => (retryCount += 1),
328-
error: {
329-
validate: () => retryCount >= maxRetries,
330-
message: () =>
331-
`The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
332-
},
333-
timeout: () => timeout(retryCount),
334-
};
325+
const baseIteratorOptions: IterableOptions<
326+
GetApiKeyResponse | undefined
327+
> = {
328+
aggregator: () => (retryCount += 1),
329+
error: {
330+
validate: () => retryCount >= maxRetries,
331+
message: () =>
332+
`The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
333+
},
334+
timeout: () => timeout(retryCount),
335+
};
335336

336337
if (operation === 'update') {
337338
if (!apiKey) {
@@ -366,9 +367,15 @@ export function createSearchClient({
366367
return createIterablePromise({
367368
...baseIteratorOptions,
368369
func: () =>
369-
this.getApiKey({ key }, requestOptions).catch((error) => error),
370-
validate: (error: ApiError) =>
371-
operation === 'add' ? error.status !== 404 : error.status === 404,
370+
this.getApiKey({ key }, requestOptions).catch((error: ApiError) => {
371+
if (error.status === 404) {
372+
return undefined;
373+
}
374+
375+
throw error;
376+
}),
377+
validate: (response) =>
378+
operation === 'add' ? response !== undefined : response === undefined,
372379
});
373380
},
374381

clients/algoliasearch-client-php/lib/Api/SearchClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,8 +2817,8 @@ function ($res) {return 'published' === $res['status']; },
28172817
/**
28182818
* Wait for an API key to be added, updated or deleted based on a given `operation`.
28192819
*
2820-
* @param string $operation the `operation` that was done on a `key`
28212820
* @param string $key the `key` that has been added, deleted or updated
2821+
* @param string $operation the `operation` that was done on a `key`
28222822
* @param array $apiKey necessary to know if an `update` operation has been processed, compare fields of the response with it
28232823
* @param null|int $maxRetries Maximum number of retries
28242824
* @param null|int $timeout Timeout
@@ -2827,8 +2827,8 @@ function ($res) {return 'published' === $res['status']; },
28272827
* @throws ExceededRetriesException
28282828
*/
28292829
public function waitForApiKey(
2830-
$operation,
28312830
$key,
2831+
$operation,
28322832
$apiKey = null,
28332833
$maxRetries = null,
28342834
$timeout = null,
@@ -2842,14 +2842,14 @@ public function waitForApiKey(
28422842
$maxRetries = $this->config->getDefaultMaxRetries();
28432843
}
28442844

2845-
Helpers::retryForApiKeyUntil(
2845+
return Helpers::retryForApiKeyUntil(
28462846
$operation,
28472847
$this,
28482848
$key,
28492849
$apiKey,
28502850
$maxRetries,
28512851
$timeout,
2852-
null,
2852+
'Algolia\AlgoliaSearch\Support\Helpers::linearTimeout',
28532853
$requestOptions
28542854
);
28552855
}

clients/algoliasearch-client-php/lib/Support/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static function retryForApiKeyUntil(
166166
// In case of a deletion, if there was an error, the $key has been deleted as it should be
167167
if (
168168
'delete' === $operation
169-
&& $e->getCode() === 404
169+
&& 404 === $e->getCode()
170170
) {
171171
return null;
172172
}

clients/algoliasearch-client-python/algoliasearch/search/client.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,13 @@ def _aggregator(_: GetTaskResponse) -> None:
254254

255255
async def wait_for_api_key(
256256
self,
257-
operation: str,
258257
key: str,
258+
operation: str,
259259
api_key: Optional[ApiKey] = None,
260260
max_retries: int = 50,
261261
timeout: RetryTimeout = RetryTimeout(),
262262
request_options: Optional[Union[dict, RequestOptions]] = None,
263-
) -> GetApiKeyResponse:
263+
) -> GetApiKeyResponse | None:
264264
"""
265265
Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
266266
"""
@@ -271,7 +271,7 @@ async def wait_for_api_key(
271271
"`apiKey` is required when waiting for an `update` operation."
272272
)
273273

274-
async def _func(_prev: GetApiKeyResponse) -> GetApiKeyResponse:
274+
async def _func(_prev: GetApiKeyResponse | None) -> GetApiKeyResponse | None:
275275
try:
276276
return await self.get_api_key(key=key, request_options=request_options)
277277
except RequestException as e:
@@ -281,20 +281,25 @@ async def _func(_prev: GetApiKeyResponse) -> GetApiKeyResponse:
281281
return None
282282
raise e
283283

284-
def _aggregator(_: GetApiKeyResponse) -> None:
284+
def _aggregator(_: GetApiKeyResponse | None) -> None:
285285
self._retry_count += 1
286286

287-
def _validate(_resp: GetApiKeyResponse) -> bool:
287+
def _validate(_resp: GetApiKeyResponse | None) -> bool:
288288
if operation == "update":
289-
for field in api_key:
290-
if isinstance(api_key[field], list) and isinstance(
291-
_resp[field], list
289+
resp_dict = _resp.to_dict()
290+
api_key_dict = (
291+
api_key.to_dict() if isinstance(api_key, ApiKey) else api_key
292+
)
293+
for field in api_key_dict:
294+
if isinstance(api_key_dict[field], list) and isinstance(
295+
resp_dict[field], list
292296
):
293-
if len(api_key[field]) != len(_resp[field]) or any(
294-
v != _resp[field][i] for i, v in enumerate(api_key[field])
297+
if len(api_key_dict[field]) != len(resp_dict[field]) or any(
298+
v != resp_dict[field][i]
299+
for i, v in enumerate(api_key_dict[field])
295300
):
296301
return False
297-
elif api_key[field] != _resp[field]:
302+
elif api_key_dict[field] != resp_dict[field]:
298303
return False
299304
return True
300305
elif operation == "add":

clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,16 +3179,16 @@ def wait_for_app_task(
31793179

31803180
# Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
31813181
#
3182-
# @param operation [String] the `operation` that was done on a `key`.
31833182
# @param key [String] the `key` that has been added, deleted or updated.
3183+
# @param operation [String] the `operation` that was done on a `key`.
31843184
# @param api_key [Hash] necessary to know if an `update` operation has been processed, compare fields of the response with it.
31853185
# @param max_retries [Integer] the maximum number of retries.
31863186
# @param timeout [Proc] the function to decide how long to wait between retries.
31873187
# @param request_options [Hash] the requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
31883188
# @return [Http::Response] the last get_api_key response
31893189
def wait_for_api_key(
3190-
operation,
31913190
key,
3191+
operation,
31923192
api_key = {},
31933193
max_retries = 50,
31943194
timeout = -> (retry_count) { [retry_count * 200, 5000].min },
@@ -3198,19 +3198,15 @@ def wait_for_api_key(
31983198
if operation == "update"
31993199
raise ArgumentError, "`api_key` is required when waiting for an `update` operation." if api_key.nil?
32003200
while retries < max_retries
3201-
begin
3202-
updatad_key = get_api_key(key, request_options)
3203-
updated_key_hash = updatad_key.to_hash
3204-
equals = true
3205-
api_key.to_hash.each do |k, v|
3206-
equals &&= updated_key_hash[k] == v
3207-
end
3208-
3209-
return updatad_key if equals
3210-
rescue AlgoliaError => e
3211-
raise e unless e.code == 404
3201+
updated_key = get_api_key(key, request_options)
3202+
updated_key_hash = updated_key.to_hash
3203+
equals = true
3204+
api_key.to_hash.each do |k, v|
3205+
equals &&= updated_key_hash[k] == v
32123206
end
32133207

3208+
return updated_key if equals
3209+
32143210
retries += 1
32153211
sleep(timeout.call(retries) / 1000.0)
32163212
end
@@ -3222,8 +3218,12 @@ def wait_for_api_key(
32223218
begin
32233219
res = get_api_key(key, request_options)
32243220
return res if operation == "add"
3225-
rescue AlgoliaError => e
3226-
return res if operation == "delete" && e.code == 404
3221+
rescue AlgoliaHttpError => e
3222+
if e.code == 404
3223+
return nil if operation == "delete"
3224+
else
3225+
raise e
3226+
end
32273227
end
32283228

32293229
retries += 1

0 commit comments

Comments
 (0)