Просмотр исходного кода

Remove unused Elasticsearch client types and client implementation

Shun Miyazawa 9 месяцев назад
Родитель
Сommit
1098c2799d

+ 0 - 114
apps/app/src/server/service/search-delegator/elasticsearch-client-types.ts

@@ -1,114 +0,0 @@
-// TODO: https://redmine.weseek.co.jp/issues/168415
-/* eslint-disable camelcase */
-export type NodesInfoResponse = {
-  nodes: Record<
-    string,
-    {
-      version: string
-      plugins: Plugin[]
-    }
-  >
-}
-
-export type CatIndicesResponse = {
-  index: string
-}[]
-
-export type IndicesExistsResponse = boolean
-
-export type IndicesExistsAliasResponse = boolean
-
-export type CatAliasesResponse = {
-  alias: string
-  index: string
-  filter: string
-}[]
-
-export type BulkResponse = {
-  took: number
-  errors: boolean
-  items: Record<string, any>[]
-}
-
-export type SearchResponse = {
-  took: number
-  timed_out: boolean
-  _shards: {
-    total: number
-    successful: number
-    skipped: number
-    failed: number
-  }
-  hits: {
-    total: number | {
-      value: number
-      relation: string
-    } // 6.x.x | 7.x.x
-    max_score: number | null
-    hits: Record<string, {
-      _index: string
-      _type: string
-      _id: string
-      _score: number
-      _source: any
-    }>[]
-  }
-}
-
-export type ValidateQueryResponse = {
-  valid: boolean,
-  _shards: {
-    total: number,
-    successful: number,
-    failed: number
-  },
-  explanations: Record<string, any>[]
-}
-
-export type ClusterHealthResponse = {
-  cluster_name: string,
-  status: string,
-  timed_out: boolean,
-  number_of_nodes: number,
-  number_of_data_nodes: number,
-  active_primary_shards: number,
-  active_shards: number,
-  relocating_shards: number,
-  initializing_shards: number,
-  unassigned_shards: number,
-  delayed_unassigned_shards: number,
-  number_of_pending_tasks: number,
-  number_of_in_flight_fetch: number,
-  task_max_waiting_in_queue_millis: number,
-  active_shards_percent_as_number: number
-}
-
-export type IndicesStatsResponse = {
-  _shards: {
-    total: number,
-    successful: number,
-    failed: number
-  },
-  _all: {
-    primaries: any,
-    total: any
-  },
-  indices: any
-}
-
-export type ReindexResponse = {
-  took: number,
-  timed_out: boolean,
-  total: number,
-  updated: number,
-  created: number,
-  deleted: number,
-  batches: number,
-  noops: number,
-  version_conflicts: number,
-  retries: number,
-  throttled_millis: number,
-  requests_per_second: number,
-  throttled_until_millis: number,
-  failures: any | null
-}

+ 0 - 126
apps/app/src/server/service/search-delegator/elasticsearch-client.ts

@@ -1,126 +0,0 @@
-// TODO: https://redmine.weseek.co.jp/issues/168415
-/* eslint-disable implicit-arrow-linebreak */
-/* eslint-disable no-confusing-arrow */
-import type {
-  ClientOptions as ES7ClientOptions,
-  ApiResponse as ES7ApiResponse,
-  RequestParams as ES7RequestParams,
-} from '@elastic/elasticsearch7';
-import {
-  Client as ES7Client,
-} from '@elastic/elasticsearch7';
-import type { ClientOptions as ES8ClientOptions, estypes } from '@elastic/elasticsearch8';
-import { Client as ES8Client } from '@elastic/elasticsearch8';
-
-import type {
-  BulkResponse,
-  CatAliasesResponse,
-  CatIndicesResponse,
-  IndicesExistsResponse,
-  IndicesExistsAliasResponse,
-  NodesInfoResponse,
-  SearchResponse,
-  ValidateQueryResponse,
-  ClusterHealthResponse,
-  IndicesStatsResponse,
-  ReindexResponse,
-} from './elasticsearch-client-types';
-
-
-type ElasticsearchClientParams =
-  | [ isES7: true, options: ES7ClientOptions, rejectUnauthorized: boolean ]
-  | [ isES7: false, options: ES8ClientOptions, rejectUnauthorized: boolean ]
-
-export default class ElasticsearchClient {
-
-  private client: ES7Client | ES8Client;
-
-  constructor(...params: ElasticsearchClientParams) {
-    const [isES7, options, rejectUnauthorized] = params;
-
-    this.client = isES7
-      ? new ES7Client({ ...options, ssl: { rejectUnauthorized } })
-      : new ES8Client({ ...options, tls: { rejectUnauthorized } });
-  }
-
-  async bulk(params: ES7RequestParams.Bulk & estypes.BulkRequest): Promise<BulkResponse | estypes.BulkResponse> {
-    return this.client instanceof ES7Client ? (await this.client.bulk(params)).body as BulkResponse : this.client.bulk(params);
-  }
-
-  // TODO: cat is not used in current Implementation, remove cat?
-  cat = {
-    aliases: (params: ES7RequestParams.CatAliases & estypes.CatAliasesRequest): Promise<ES7ApiResponse<CatAliasesResponse> | estypes.CatAliasesResponse> =>
-      this.client instanceof ES7Client ? this.client.cat.aliases(params) : this.client.cat.aliases(params),
-
-    indices: (params: ES7RequestParams.CatIndices & estypes.CatIndicesRequest): Promise<ES7ApiResponse<CatIndicesResponse> | estypes.CatAliasesResponse> =>
-      this.client instanceof ES7Client ? this.client.cat.indices(params) : this.client.cat.indices(params),
-  };
-
-  cluster = {
-    health: ()
-    : Promise<ES7ApiResponse<ClusterHealthResponse> | estypes.ClusterHealthResponse> =>
-      this.client instanceof ES7Client ? this.client.cluster.health() : this.client.cluster.health(),
-  };
-
-  indices = {
-    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-    create: (params: ES7RequestParams.IndicesCreate & estypes.IndicesCreateRequest) =>
-      this.client instanceof ES7Client ? this.client.indices.create(params) : this.client.indices.create(params),
-
-    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-    delete: (params: ES7RequestParams.IndicesDelete & estypes.IndicesDeleteRequest) =>
-      this.client instanceof ES7Client ? this.client.indices.delete(params) : this.client.indices.delete(params),
-
-    exists: async(params: ES7RequestParams.IndicesExists & estypes.IndicesExistsRequest)
-    : Promise<IndicesExistsResponse | estypes.IndicesExistsResponse> =>
-      this.client instanceof ES7Client ? (await this.client.indices.exists(params)).body as IndicesExistsResponse : this.client.indices.exists(params),
-
-    existsAlias: async(params: ES7RequestParams.IndicesExistsAlias & estypes.IndicesExistsAliasRequest)
-    : Promise<IndicesExistsAliasResponse | estypes.IndicesExistsAliasResponse> =>
-      this.client instanceof ES7Client
-        ? (await this.client.indices.existsAlias(params)).body as IndicesExistsAliasResponse
-        : this.client.indices.existsAlias(params),
-
-    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-    putAlias: (params: ES7RequestParams.IndicesPutAlias & estypes.IndicesPutAliasRequest) =>
-      this.client instanceof ES7Client ? this.client.indices.putAlias(params) : this.client.indices.putAlias(params),
-
-    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-    getAlias: async(params: ES7RequestParams.IndicesGetAlias & estypes.IndicesGetAliasRequest) =>
-      this.client instanceof ES7Client ? (await this.client.indices.getAlias(params)).body : this.client.indices.getAlias(params),
-
-    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-    updateAliases: (params: ES7RequestParams.IndicesUpdateAliases & estypes.IndicesUpdateAliasesRequest) =>
-      this.client instanceof ES7Client ? this.client.indices.updateAliases(params) : this.client.indices.updateAliases(params),
-
-    validateQuery: async(params: ES7RequestParams.IndicesValidateQuery & estypes.IndicesValidateQueryRequest)
-    : Promise<ValidateQueryResponse | estypes.IndicesValidateQueryResponse> =>
-      // eslint-disable-next-line max-len
-      this.client instanceof ES7Client ? (await this.client.indices.validateQuery(params)).body as ValidateQueryResponse : this.client.indices.validateQuery(params),
-
-    stats: async(params: ES7RequestParams.IndicesStats & estypes.IndicesStatsRequest)
-    : Promise<IndicesStatsResponse | estypes.IndicesStatsResponse> =>
-      this.client instanceof ES7Client ? (await this.client.indices.stats(params)).body as IndicesStatsResponse : this.client.indices.stats(params),
-  };
-
-  nodes = {
-    info: (): Promise<ES7ApiResponse<NodesInfoResponse> | estypes.NodesInfoResponse> =>
-      (this.client instanceof ES7Client ? this.client.nodes.info() : this.client.nodes.info()),
-  };
-
-  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-  ping() {
-    return this.client instanceof ES7Client ? this.client.ping() : this.client.ping();
-  }
-
-  reindex(indexName: string, tmpIndexName: string): Promise<ES7ApiResponse<ReindexResponse> | estypes.ReindexResponse> {
-    return this.client instanceof ES7Client
-      ? this.client.reindex({ wait_for_completion: false, body: { source: { index: indexName }, dest: { index: tmpIndexName } } })
-      : this.client.reindex({ wait_for_completion: false, source: { index: indexName }, dest: { index: tmpIndexName } });
-  }
-
-  async search(params: ES7RequestParams.Search & estypes.SearchRequest): Promise<SearchResponse | estypes.SearchResponse> {
-    return this.client instanceof ES7Client ? (await this.client.search(params)).body as SearchResponse : this.client.search(params);
-  }
-
-}