diff --git a/src/plugins/region_map/server/plugin.js b/src/plugins/region_map/server/plugin.js deleted file mode 100644 index 14aeb0801d23..000000000000 --- a/src/plugins/region_map/server/plugin.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { OpensearchService } from './services'; -import { opensearch } from '../server/routes'; -import { getUiSettings } from './ui_settings'; - -export class RegionMapPlugin { - constructor(initializerContext) { - this.logger = initializerContext.logger.get(); - } - - async setup(core) { - const opensearchClient = core.opensearch.legacy.createClient('opensearch'); - - // Initialize services - const opensearchService = new OpensearchService(opensearchClient); - - // Register server side APIs - const router = core.http.createRouter(); - core.uiSettings.register(getUiSettings()); - opensearch(opensearchService, router); - - return {}; - } - - async start() { - return {}; - } - - async stop() {} -} diff --git a/src/plugins/region_map/server/plugin.ts b/src/plugins/region_map/server/plugin.ts new file mode 100644 index 000000000000..6b9c7c190fc0 --- /dev/null +++ b/src/plugins/region_map/server/plugin.ts @@ -0,0 +1,42 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + PluginInitializerContext, + CoreSetup, + CoreStart, + Plugin, + Logger, +} from 'opensearch-dashboards/server'; + +import { OpenSearchService } from './services'; +import { registerGeospatialRoutes } from '../server/routes'; +import { getUiSettings } from './ui_settings'; +import { RegionMapPluginSetup, RegionMapPluginStart } from './types'; + +export class RegionMapPlugin implements Plugin { + private readonly logger: Logger; + + constructor(initializerContext: PluginInitializerContext) { + this.logger = initializerContext.logger.get(); + } + + public setup(core: CoreSetup) { + this.logger.debug('RegionMap: Setup'); + const opensearchClient = core.opensearch.legacy.createClient('opensearch'); + const opensearchService = new OpenSearchService(opensearchClient); + const router = core.http.createRouter(); + core.uiSettings.register(getUiSettings()); + registerGeospatialRoutes(opensearchService, router); + return {}; + } + + public start(_core: CoreStart) { + this.logger.debug('RegionMap: Started'); + return {}; + } + + public stop() {} +} diff --git a/src/plugins/region_map/server/routes/index.ts b/src/plugins/region_map/server/routes/index.ts index bdbd7bdca88e..37d50c83f609 100644 --- a/src/plugins/region_map/server/routes/index.ts +++ b/src/plugins/region_map/server/routes/index.ts @@ -3,6 +3,4 @@ * SPDX-License-Identifier: Apache-2.0 */ -import opensearch from './opensearch'; - -export { opensearch }; +export { registerGeospatialRoutes } from './opensearch'; diff --git a/src/plugins/region_map/server/routes/opensearch.ts b/src/plugins/region_map/server/routes/opensearch.ts index 2d67bc9c4e32..ad5116aefb46 100644 --- a/src/plugins/region_map/server/routes/opensearch.ts +++ b/src/plugins/region_map/server/routes/opensearch.ts @@ -4,9 +4,10 @@ */ import { schema } from '@osd/config-schema'; +import { IRouter } from 'opensearch-dashboards/server'; +import { OpenSearchService } from '../services'; -// eslint-disable-next-line import/no-default-export -export default function (services, router) { +export function registerGeospatialRoutes(services: OpenSearchService, router: IRouter) { router.post( { path: '/api/geospatial/_indices', diff --git a/src/plugins/region_map/server/services/index.js b/src/plugins/region_map/server/services/index.js deleted file mode 100644 index 63a48fdfdd4d..000000000000 --- a/src/plugins/region_map/server/services/index.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import OpensearchService from './opensearch_service'; - -export { OpensearchService }; diff --git a/src/plugins/region_map/server/services/index.ts b/src/plugins/region_map/server/services/index.ts new file mode 100644 index 000000000000..bbbb71084f15 --- /dev/null +++ b/src/plugins/region_map/server/services/index.ts @@ -0,0 +1,6 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export { OpenSearchService } from './opensearch_service'; diff --git a/src/plugins/region_map/server/services/opensearch_service.js b/src/plugins/region_map/server/services/opensearch_service.ts similarity index 66% rename from src/plugins/region_map/server/services/opensearch_service.js rename to src/plugins/region_map/server/services/opensearch_service.ts index e9be890b72f0..5efdd6d13072 100644 --- a/src/plugins/region_map/server/services/opensearch_service.js +++ b/src/plugins/region_map/server/services/opensearch_service.ts @@ -3,12 +3,25 @@ * SPDX-License-Identifier: Apache-2.0 */ -export default class OpensearchService { - constructor(esDriver) { +import { + ILegacyCustomClusterClient, + IOpenSearchDashboardsResponse, + OpenSearchDashboardsRequest, + OpenSearchDashboardsResponseFactory, + RequestHandlerContext, +} from 'opensearch-dashboards/server'; + +export class OpenSearchService { + esDriver: ILegacyCustomClusterClient; + constructor(esDriver: ILegacyCustomClusterClient) { this.esDriver = esDriver; } - getMappings = async (context, req, res) => { + getMappings = async ( + context: RequestHandlerContext, + req: OpenSearchDashboardsRequest, + res: OpenSearchDashboardsResponseFactory + ): Promise> => { try { const { index } = req.body; const { callAsCurrentUser } = this.esDriver.asScoped(req); @@ -29,7 +42,11 @@ export default class OpensearchService { } }; - search = async (context, req, res) => { + search = async ( + context: RequestHandlerContext, + req: OpenSearchDashboardsRequest, + res: OpenSearchDashboardsResponseFactory + ): Promise> => { try { const { query, index, size } = req.body; const params = { index, size, body: query }; @@ -51,7 +68,11 @@ export default class OpensearchService { } }; - getIndex = async (context, req, res) => { + getIndex = async ( + context: RequestHandlerContext, + req: OpenSearchDashboardsRequest, + res: OpenSearchDashboardsResponseFactory + ): Promise> => { try { const { index } = req.body; const { callAsCurrentUser } = this.esDriver.asScoped(req);