fix: deprecate getAliases instead of removing it

Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
This commit is contained in:
Thomas Cardonne
2024-05-08 12:30:16 +02:00
parent 7019b5328e
commit 59a4bea757
3 changed files with 67 additions and 0 deletions
@@ -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[];
@@ -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()
@@ -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()
@@ -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);
@@ -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);
@@ -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);