Skip to content

Commit e297b32

Browse files
algolia-botmillotp
andcommitted
feat(clients): add optionnal scopes to replaceAllObjects [skip-bc] (generated)
algolia/api-clients-automation#4296 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent aaf5e87 commit e297b32

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/client-search/model/clientMethodProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { OperationIndexParams } from '../model/operationIndexParams';
2323

2424
import type { Rule } from '../model/rule';
2525

26+
import type { ScopeType } from '../model/scopeType';
2627
import type { SearchDictionaryEntriesParams } from '../model/searchDictionaryEntriesParams';
2728

2829
import type { SearchForFacetValuesRequest } from '../model/searchForFacetValuesRequest';
@@ -870,4 +871,9 @@ export type ReplaceAllObjectsOptions = {
870871
* The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
871872
*/
872873
batchSize?: number;
874+
875+
/**
876+
* The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
877+
*/
878+
scopes?: Array<ScopeType>;
873879
};

packages/client-search/src/searchClient.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,23 +633,28 @@ export function createSearchClient({
633633
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
634634
* @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
635635
* @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.
636+
* @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
636637
* @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.
637638
*/
638639
async replaceAllObjects(
639-
{ indexName, objects, batchSize }: ReplaceAllObjectsOptions,
640+
{ indexName, objects, batchSize, scopes }: ReplaceAllObjectsOptions,
640641
requestOptions?: RequestOptions,
641642
): Promise<ReplaceAllObjectsResponse> {
642643
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;
643644
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
644645

646+
if (scopes === undefined) {
647+
scopes = ['settings', 'rules', 'synonyms'];
648+
}
649+
645650
try {
646651
let copyOperationResponse = await this.operationIndex(
647652
{
648653
indexName,
649654
operationIndexParams: {
650655
operation: 'copy',
651656
destination: tmpIndexName,
652-
scope: ['settings', 'rules', 'synonyms'],
657+
scope: scopes,
653658
},
654659
},
655660
requestOptions,
@@ -671,7 +676,7 @@ export function createSearchClient({
671676
operationIndexParams: {
672677
operation: 'copy',
673678
destination: tmpIndexName,
674-
scope: ['settings', 'rules', 'synonyms'],
679+
scope: scopes,
675680
},
676681
},
677682
requestOptions,

0 commit comments

Comments
 (0)