Skip to content

Commit

Permalink
fix: deprecate getAliases instead of removing it
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
  • Loading branch information
tcardonne committed May 8, 2024
1 parent 8f88db3 commit 2dbc917
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/search-backend-module-elasticsearch/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ export class ElasticSearchClientWrapper {
static fromClientOptions(
options: ElasticSearchClientOptions,
): ElasticSearchClientWrapper;
// @deprecated (undocumented)
getAliases(options: {
aliases: string[];
}):
| TransportRequestPromise<ApiResponse<Record<string, any>, unknown>>
| TransportRequestPromise_2<ApiResponse_2<Record<string, any>, unknown>>;
// (undocumented)
indexExists(options: {
index: string | string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jest.mock('@elastic/elasticsearch', () => ({
search: jest
.fn()
.mockImplementation(async args => ({ client: 'es', args })),
cat: {
aliases: jest
.fn()
.mockImplementation(async args => ({ client: 'es', args })),
},
helpers: {
bulk: jest
.fn()
Expand Down Expand Up @@ -60,6 +65,11 @@ jest.mock('@opensearch-project/opensearch', () => ({
search: jest
.fn()
.mockImplementation(async args => ({ client: 'os', args })),
cat: {
aliases: jest
.fn()
.mockImplementation(async args => ({ client: 'os', args })),
},
helpers: {
bulk: jest
.fn()
Expand Down Expand Up @@ -189,6 +199,20 @@ describe('ElasticSearchClientWrapper', () => {
expect(result.args).toStrictEqual(input);
});

it('getAliases', async () => {
const wrapper = ElasticSearchClientWrapper.fromClientOptions(esOptions);

const input = { aliases: ['xyz'] };
const result = (await wrapper.getAliases(input)) as any;

// Should call the OpenSearch client with expected input.
expect(result.client).toBe('es');
expect(result.args).toStrictEqual({
format: 'json',
name: input.aliases,
});
});

it('updateAliases', async () => {
const wrapper = ElasticSearchClientWrapper.fromClientOptions(esOptions);

Expand Down Expand Up @@ -313,6 +337,20 @@ describe('ElasticSearchClientWrapper', () => {
expect(result.args).toStrictEqual(input);
});

it('getAliases', async () => {
const wrapper = ElasticSearchClientWrapper.fromClientOptions(osOptions);

const input = { aliases: ['xyz'] };
const result = (await wrapper.getAliases(input)) as any;

// Should call the OpenSearch client with expected input.
expect(result.client).toBe('os');
expect(result.args).toStrictEqual({
format: 'json',
name: input.aliases,
});
});

it('updateAliases', async () => {
const wrapper = ElasticSearchClientWrapper.fromClientOptions(osOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ export class ElasticSearchClientWrapper {
throw new Error('No client defined');
}

/**
* @deprecated unused by the ElasticSearch Engine, will be removed in the future
*/
getAliases(options: { aliases: string[] }) {
const { aliases } = options;

if (this.openSearchClient) {
return this.openSearchClient.cat.aliases({
format: 'json',
name: aliases,
});
}

if (this.elasticSearchClient) {
return this.elasticSearchClient.cat.aliases({
format: 'json',
name: aliases,
});
}

throw new Error('No client defined');
}

createIndex(options: { index: string }) {
if (this.openSearchClient) {
return this.openSearchClient.indices.create(options);
Expand Down

0 comments on commit 2dbc917

Please sign in to comment.