Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/algoliasearch/src/builds/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ export type SearchIndex = BaseSearchIndex & {
readonly replaceAllSynonyms: (
synonyms: readonly Synonym[],
requestOptions?: RequestOptions &
Pick<SaveSynonymsOptions, Exclude<keyof SaveSynonymsOptions, 'replaceExistingSynonyms'>>
Pick<
SaveSynonymsOptions,
Exclude<keyof SaveSynonymsOptions, 'clearExistingSynonyms' | 'replaceExistingSynonyms'>
>
) => Readonly<WaitablePromise<SaveSynonymsResponse>>;
readonly searchRules: (
query: string,
Expand Down
5 changes: 4 additions & 1 deletion packages/algoliasearch/src/builds/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ export type SearchIndex = BaseSearchIndex & {
readonly replaceAllSynonyms: (
synonyms: readonly Synonym[],
requestOptions?: RequestOptions &
Pick<SaveSynonymsOptions, Exclude<keyof SaveSynonymsOptions, 'replaceExistingSynonyms'>>
Pick<
SaveSynonymsOptions,
Exclude<keyof SaveSynonymsOptions, 'clearExistingSynonyms' | 'replaceExistingSynonyms'>
>
) => Readonly<WaitablePromise<SaveSynonymsResponse>>;
readonly searchRules: (
query: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ export const replaceAllSynonyms = (base: SearchIndex) => {
return (
synonyms: readonly Synonym[],
requestOptions?: RequestOptions &
Pick<SaveSynonymsOptions, Exclude<keyof SaveSynonymsOptions, 'replaceExistingSynonyms'>>
Pick<
SaveSynonymsOptions,
Exclude<keyof SaveSynonymsOptions, 'clearExistingSynonyms' | 'replaceExistingSynonyms'>
>
): Readonly<WaitablePromise<SaveSynonymsResponse>> => {
return saveSynonyms(base)(synonyms, {
...requestOptions,
replaceExistingSynonyms: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if someone called replaceAllSynonyms with replaceExistingSynonyms: false, this would be a breaking change, however it's an excluded parameter, therefore not using typescript and not supported usage (wrong parameters)

clearExistingSynonyms: true,
});
};
};
5 changes: 3 additions & 2 deletions packages/client-search/src/methods/index/saveSynonyms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export const saveSynonyms = (base: SearchIndex) => {
synonyms: readonly Synonym[],
requestOptions?: SaveSynonymsOptions & RequestOptions
): Readonly<WaitablePromise<SaveSynonymsResponse>> => {
const { forwardToReplicas, replaceExistingSynonyms, ...options } = requestOptions || {};
const { forwardToReplicas, clearExistingSynonyms, replaceExistingSynonyms, ...options } =
requestOptions || {};
const mappedRequestOptions = createMappedRequestOptions(options);

if (forwardToReplicas) {
mappedRequestOptions.queryParameters.forwardToReplicas = 1; // eslint-disable-line functional/immutable-data
}

if (replaceExistingSynonyms) {
if (replaceExistingSynonyms || clearExistingSynonyms) {
mappedRequestOptions.queryParameters.replaceExistingSynonyms = 1; // eslint-disable-line functional/immutable-data
}

Expand Down
6 changes: 6 additions & 0 deletions packages/client-search/src/types/SaveSynonymsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export type SaveSynonymsOptions = {

/**
* If the existing synonyms should be removed.
* @deprecated use clearExistingSynonyms
*/
readonly replaceExistingSynonyms?: boolean;

/**
* If the existing synonyms should be removed.
*/
readonly clearExistingSynonyms?: boolean;
};