Skip to content

Commit c07eab7

Browse files
chore: generated code for commit e89bb79. [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent e89bb79 commit c07eab7

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,28 @@ export type GetSecuredApiKeyRemainingValidityOptions = {
806806
securedApiKey: string;
807807
};
808808

809+
export type DeleteObjectsOptions = Pick<ChunkedBatchOptions, 'indexName'> & {
810+
/**
811+
* The objectIDs to delete.
812+
*/
813+
objectIDs: string[];
814+
};
815+
816+
export type PartialUpdateObjectsOptions = Pick<
817+
ChunkedBatchOptions,
818+
'indexName' | 'objects'
819+
> & {
820+
/**
821+
*To be provided if non-existing objects are passed, otherwise, the call will fail.
822+
*/
823+
createIfNotExists?: boolean;
824+
};
825+
826+
export type SaveObjectsOptions = Pick<
827+
ChunkedBatchOptions,
828+
'indexName' | 'objects'
829+
>;
830+
809831
export type ChunkedBatchOptions = ReplaceAllObjectsOptions & {
810832
/**
811833
* The `batch` `action` to perform on the given array of `objects`, defaults to `addObject`.

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

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ import type { BrowseResponse } from '../model/browseResponse';
2727
import type {
2828
BrowseOptions,
2929
ChunkedBatchOptions,
30+
DeleteObjectsOptions,
31+
PartialUpdateObjectsOptions,
3032
ReplaceAllObjectsOptions,
33+
SaveObjectsOptions,
3134
WaitForApiKeyOptions,
32-
WaitForTaskOptions,
3335
WaitForAppTaskOptions,
36+
WaitForTaskOptions,
3437
AddOrUpdateObjectProps,
3538
AssignUserIdProps,
3639
BatchProps,
@@ -577,6 +580,74 @@ export function createSearchClient({
577580
return responses;
578581
},
579582

583+
/**
584+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
585+
*
586+
* @summary Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
587+
* @param saveObjects - The `saveObjects` object.
588+
* @param saveObjects.indexName - The `indexName` to save `objects` in.
589+
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
590+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
591+
*/
592+
async saveObjects(
593+
{ indexName, objects }: SaveObjectsOptions,
594+
requestOptions?: RequestOptions
595+
): Promise<BatchResponse[]> {
596+
return await this.chunkedBatch(
597+
{ indexName, objects, action: 'addObject' },
598+
requestOptions
599+
);
600+
},
601+
602+
/**
603+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
604+
*
605+
* @summary Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
606+
* @param deleteObjects - The `deleteObjects` object.
607+
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
608+
* @param deleteObjects.objectIDs - The objectIDs to delete.
609+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
610+
*/
611+
async deleteObjects(
612+
{ indexName, objectIDs }: DeleteObjectsOptions,
613+
requestOptions?: RequestOptions
614+
): Promise<BatchResponse[]> {
615+
return await this.chunkedBatch(
616+
{
617+
indexName,
618+
objects: objectIDs.map((objectID) => ({ objectID })),
619+
action: 'deleteObject',
620+
},
621+
requestOptions
622+
);
623+
},
624+
625+
/**
626+
* Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
627+
*
628+
* @summary Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
629+
* @param partialUpdateObjects - The `partialUpdateObjects` object.
630+
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
631+
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
632+
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
633+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
634+
*/
635+
async partialUpdateObjects(
636+
{ indexName, objects, createIfNotExists }: PartialUpdateObjectsOptions,
637+
requestOptions?: RequestOptions
638+
): Promise<BatchResponse[]> {
639+
return await this.chunkedBatch(
640+
{
641+
indexName,
642+
objects,
643+
action: createIfNotExists
644+
? 'partialUpdateObject'
645+
: 'partialUpdateObjectNoCreate',
646+
},
647+
requestOptions
648+
);
649+
},
650+
580651
/**
581652
* Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
582653
* See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation details.
@@ -586,7 +657,7 @@ export function createSearchClient({
586657
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
587658
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
588659
* @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
589-
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
660+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch`, `operationIndex` and `getTask` method and merged with the transporter requestOptions.
590661
*/
591662
async replaceAllObjects(
592663
{ indexName, objects, batchSize }: ReplaceAllObjectsOptions,
@@ -647,7 +718,6 @@ export function createSearchClient({
647718

648719
return { copyOperationResponse, batchResponses, moveOperationResponse };
649720
},
650-
651721
/**
652722
* Creates a new API key with specific permissions and restrictions.
653723
*

0 commit comments

Comments
 (0)