Skip to content

Commit

Permalink
feat(clients): expose waitForTasks to batch helpers [skip-bc] (genera…
Browse files Browse the repository at this point in the history
…ted)

algolia/api-clients-automation#4030

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Oct 28, 2024
1 parent 4866f7f commit 86eb124
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/client-search/model/clientMethodProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,21 +824,21 @@ export type SearchClientNodeHelpers = {
getSecuredApiKeyRemainingValidity: (opts: GetSecuredApiKeyRemainingValidityOptions) => number;
};

export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName'> & {
export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'waitForTasks'> & {
/**
* The objectIDs to delete.
*/
objectIDs: string[];
};

export type PartialUpdateObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects'> & {
export type PartialUpdateObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks'> & {
/**
*To be provided if non-existing objects are passed, otherwise, the call will fail.
*/
createIfNotExists?: boolean;
};

export type SaveObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects'>;
export type SaveObjectsOptions = Pick<ChunkedBatchOptions, 'indexName' | 'objects' | 'waitForTasks'>;

export type ChunkedBatchOptions = ReplaceAllObjectsOptions & {
/**
Expand Down
13 changes: 9 additions & 4 deletions packages/client-search/src/searchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,14 @@ export function createSearchClient({
* @param saveObjects - The `saveObjects` object.
* @param saveObjects.indexName - The `indexName` to save `objects` in.
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
* @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
*/
async saveObjects(
{ indexName, objects }: SaveObjectsOptions,
{ indexName, objects, waitForTasks }: SaveObjectsOptions,
requestOptions?: RequestOptions,
): Promise<BatchResponse[]> {
return await this.chunkedBatch({ indexName, objects, action: 'addObject' }, requestOptions);
return await this.chunkedBatch({ indexName, objects, action: 'addObject', waitForTasks }, requestOptions);
},

/**
Expand All @@ -566,17 +567,19 @@ export function createSearchClient({
* @param deleteObjects - The `deleteObjects` object.
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
* @param deleteObjects.objectIDs - The objectIDs to delete.
* @param deleteObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
*/
async deleteObjects(
{ indexName, objectIDs }: DeleteObjectsOptions,
{ indexName, objectIDs, waitForTasks }: DeleteObjectsOptions,
requestOptions?: RequestOptions,
): Promise<BatchResponse[]> {
return await this.chunkedBatch(
{
indexName,
objects: objectIDs.map((objectID) => ({ objectID })),
action: 'deleteObject',
waitForTasks,
},
requestOptions,
);
Expand All @@ -590,17 +593,19 @@ export function createSearchClient({
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
* @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
async partialUpdateObjects(
{ indexName, objects, createIfNotExists }: PartialUpdateObjectsOptions,
{ indexName, objects, createIfNotExists, waitForTasks }: PartialUpdateObjectsOptions,
requestOptions?: RequestOptions,
): Promise<BatchResponse[]> {
return await this.chunkedBatch(
{
indexName,
objects,
action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate',
waitForTasks,
},
requestOptions,
);
Expand Down

0 comments on commit 86eb124

Please sign in to comment.