From 9d3ff6680f2fe0cf26da2bcb16d3436cba6331a4 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 12 Oct 2021 11:49:21 +0200 Subject: [PATCH] Move router and *Service to service folder Signed-off-by: Johan Haals --- plugins/catalog-backend/src/index.ts | 1 + .../src/legacy/service/router.test.ts | 2 +- .../src/legacy/service/router.ts | 2 +- .../src/next/NextCatalogBuilder.ts | 8 +-- plugins/catalog-backend/src/next/index.ts | 11 +---- plugins/catalog-backend/src/next/types.ts | 34 +------------ .../DefaultLocationService.test.ts | 2 +- .../DefaultLocationService.ts | 5 +- .../DefaultRefreshService.test.ts | 0 .../DefaultRefreshService.ts | 0 .../src/{next => service}/NextRouter.test.ts | 2 +- .../src/{next => service}/NextRouter.ts | 0 plugins/catalog-backend/src/service/index.ts | 19 +++++++ plugins/catalog-backend/src/service/types.ts | 49 +++++++++++++++++++ 14 files changed, 82 insertions(+), 53 deletions(-) rename plugins/catalog-backend/src/{next => service}/DefaultLocationService.test.ts (99%) rename plugins/catalog-backend/src/{next => service}/DefaultLocationService.ts (95%) rename plugins/catalog-backend/src/{next => service}/DefaultRefreshService.test.ts (100%) rename plugins/catalog-backend/src/{next => service}/DefaultRefreshService.ts (100%) rename plugins/catalog-backend/src/{next => service}/NextRouter.test.ts (99%) rename plugins/catalog-backend/src/{next => service}/NextRouter.ts (100%) create mode 100644 plugins/catalog-backend/src/service/index.ts create mode 100644 plugins/catalog-backend/src/service/types.ts diff --git a/plugins/catalog-backend/src/index.ts b/plugins/catalog-backend/src/index.ts index 0c72926210..5fe0ca2483 100644 --- a/plugins/catalog-backend/src/index.ts +++ b/plugins/catalog-backend/src/index.ts @@ -28,3 +28,4 @@ export * from './util'; export * from './next'; export * from './processing'; export * from './providers'; +export * from './service'; diff --git a/plugins/catalog-backend/src/legacy/service/router.test.ts b/plugins/catalog-backend/src/legacy/service/router.test.ts index d15d3799b5..edc7d852ac 100644 --- a/plugins/catalog-backend/src/legacy/service/router.test.ts +++ b/plugins/catalog-backend/src/legacy/service/router.test.ts @@ -25,7 +25,7 @@ import { LocationResponse, LocationsCatalog } from '../catalog/types'; import { HigherOrderOperation } from '../ingestion/types'; import { createRouter } from './router'; import { basicEntityFilter } from '../../service/request'; -import { RefreshService } from '../../next'; +import { RefreshService } from '../../service'; describe('createRouter readonly disabled', () => { let entitiesCatalog: jest.Mocked>; diff --git a/plugins/catalog-backend/src/legacy/service/router.ts b/plugins/catalog-backend/src/legacy/service/router.ts index 4dfa9e49f9..e7d097a9c7 100644 --- a/plugins/catalog-backend/src/legacy/service/router.ts +++ b/plugins/catalog-backend/src/legacy/service/router.ts @@ -34,7 +34,7 @@ import { RefreshService, LocationService, RefreshOptions, -} from '../../next/types'; +} from '../../service/types'; import { basicEntityFilter, parseEntityFilterParams, diff --git a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts index 869af1581f..e1723ff627 100644 --- a/plugins/catalog-backend/src/next/NextCatalogBuilder.ts +++ b/plugins/catalog-backend/src/next/NextCatalogBuilder.ts @@ -65,7 +65,7 @@ import { ConfigLocationEntityProvider } from '../providers/ConfigLocationEntityP import { DefaultProcessingDatabase } from '../database/DefaultProcessingDatabase'; import { applyDatabaseMigrations } from '../database/migrations'; import { DefaultCatalogProcessingEngine } from '../processing/DefaultCatalogProcessingEngine'; -import { DefaultLocationService } from './DefaultLocationService'; +import { DefaultLocationService } from '../service/DefaultLocationService'; import { DefaultLocationStore } from '../providers/DefaultLocationStore'; import { NextEntitiesCatalog } from './NextEntitiesCatalog'; import { DefaultCatalogProcessingOrchestrator } from '../processing/DefaultCatalogProcessingOrchestrator'; @@ -74,12 +74,12 @@ import { createRandomRefreshInterval, RefreshIntervalFunction, } from './refresh'; -import { createNextRouter } from './NextRouter'; -import { DefaultRefreshService } from './DefaultRefreshService'; +import { createNextRouter } from '../service/NextRouter'; +import { DefaultRefreshService } from '../service/DefaultRefreshService'; import { DefaultCatalogRulesEnforcer } from '../ingestion/CatalogRules'; import { Config } from '@backstage/config'; import { Logger } from 'winston'; -import { LocationService } from './types'; +import { LocationService } from '../service/types'; export type CatalogEnvironment = { logger: Logger; diff --git a/plugins/catalog-backend/src/next/index.ts b/plugins/catalog-backend/src/next/index.ts index cc3ad0b979..c3fa4316f5 100644 --- a/plugins/catalog-backend/src/next/index.ts +++ b/plugins/catalog-backend/src/next/index.ts @@ -16,15 +16,6 @@ export type { CatalogEnvironment } from './NextCatalogBuilder'; export { NextCatalogBuilder } from './NextCatalogBuilder'; -export { createNextRouter } from './NextRouter'; -export type { NextRouterOptions } from './NextRouter'; -export * from '../processing'; export { createRandomRefreshInterval } from './refresh'; export type { RefreshIntervalFunction } from './refresh'; -export * from '../stitching'; -export type { - LocationService, - LocationStore, - RefreshOptions, - RefreshService, -} from './types'; +export type { LocationStore } from './types'; diff --git a/plugins/catalog-backend/src/next/types.ts b/plugins/catalog-backend/src/next/types.ts index 4e3d52e205..b5888a5a3a 100644 --- a/plugins/catalog-backend/src/next/types.ts +++ b/plugins/catalog-backend/src/next/types.ts @@ -14,17 +14,7 @@ * limitations under the License. */ -import { Entity, Location, LocationSpec } from '@backstage/catalog-model'; - -export interface LocationService { - createLocation( - spec: LocationSpec, - dryRun: boolean, - ): Promise<{ location: Location; entities: Entity[]; exists?: boolean }>; - listLocations(): Promise; - getLocation(id: string): Promise; - deleteLocation(id: string): Promise; -} +import { Location, LocationSpec } from '@backstage/catalog-model'; export interface LocationStore { createLocation(spec: LocationSpec): Promise; @@ -32,25 +22,3 @@ export interface LocationStore { getLocation(id: string): Promise; deleteLocation(id: string): Promise; } - -/** - * Options for requesting a refresh of entities in the catalog. - * - * @public - */ -export type RefreshOptions = { - /** The reference to a single entity that should be refreshed */ - entityRef: string; -}; - -/** - * A service that manages refreshes of entities in the catalog. - * - * @public - */ -export interface RefreshService { - /** - * Request a refresh of entities in the catalog. - */ - refresh(options: RefreshOptions): Promise; -} diff --git a/plugins/catalog-backend/src/next/DefaultLocationService.test.ts b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts similarity index 99% rename from plugins/catalog-backend/src/next/DefaultLocationService.test.ts rename to plugins/catalog-backend/src/service/DefaultLocationService.test.ts index a089989d20..8d9dee0703 100644 --- a/plugins/catalog-backend/src/next/DefaultLocationService.test.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.test.ts @@ -16,7 +16,7 @@ import { DefaultLocationService } from './DefaultLocationService'; import { CatalogProcessingOrchestrator } from '../processing/types'; -import { LocationStore } from './types'; +import { LocationStore } from '../next/types'; describe('DefaultLocationServiceTest', () => { const orchestrator: jest.Mocked = { diff --git a/plugins/catalog-backend/src/next/DefaultLocationService.ts b/plugins/catalog-backend/src/service/DefaultLocationService.ts similarity index 95% rename from plugins/catalog-backend/src/next/DefaultLocationService.ts rename to plugins/catalog-backend/src/service/DefaultLocationService.ts index 325a2a3612..bc066823db 100644 --- a/plugins/catalog-backend/src/next/DefaultLocationService.ts +++ b/plugins/catalog-backend/src/service/DefaultLocationService.ts @@ -24,8 +24,9 @@ import { CatalogProcessingOrchestrator, DeferredEntity, } from '../processing/types'; -import { LocationService, LocationStore } from './types'; -import { locationSpecToMetadataName } from './util'; +import { LocationService } from './types'; +import { LocationStore } from '../next/types'; +import { locationSpecToMetadataName } from '../next/util'; export class DefaultLocationService implements LocationService { constructor( diff --git a/plugins/catalog-backend/src/next/DefaultRefreshService.test.ts b/plugins/catalog-backend/src/service/DefaultRefreshService.test.ts similarity index 100% rename from plugins/catalog-backend/src/next/DefaultRefreshService.test.ts rename to plugins/catalog-backend/src/service/DefaultRefreshService.test.ts diff --git a/plugins/catalog-backend/src/next/DefaultRefreshService.ts b/plugins/catalog-backend/src/service/DefaultRefreshService.ts similarity index 100% rename from plugins/catalog-backend/src/next/DefaultRefreshService.ts rename to plugins/catalog-backend/src/service/DefaultRefreshService.ts diff --git a/plugins/catalog-backend/src/next/NextRouter.test.ts b/plugins/catalog-backend/src/service/NextRouter.test.ts similarity index 99% rename from plugins/catalog-backend/src/next/NextRouter.test.ts rename to plugins/catalog-backend/src/service/NextRouter.test.ts index 489e7efdb5..57911c74fb 100644 --- a/plugins/catalog-backend/src/next/NextRouter.test.ts +++ b/plugins/catalog-backend/src/service/NextRouter.test.ts @@ -22,7 +22,7 @@ import express from 'express'; import request from 'supertest'; import { EntitiesCatalog } from '../catalog'; import { LocationService, RefreshService } from './types'; -import { basicEntityFilter } from '../service/request'; +import { basicEntityFilter } from './request'; import { createNextRouter } from './NextRouter'; describe('createNextRouter readonly disabled', () => { diff --git a/plugins/catalog-backend/src/next/NextRouter.ts b/plugins/catalog-backend/src/service/NextRouter.ts similarity index 100% rename from plugins/catalog-backend/src/next/NextRouter.ts rename to plugins/catalog-backend/src/service/NextRouter.ts diff --git a/plugins/catalog-backend/src/service/index.ts b/plugins/catalog-backend/src/service/index.ts new file mode 100644 index 0000000000..f47d796693 --- /dev/null +++ b/plugins/catalog-backend/src/service/index.ts @@ -0,0 +1,19 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type { LocationService, RefreshService, RefreshOptions } from './types'; +export { createNextRouter } from './NextRouter'; +export type { NextRouterOptions } from './NextRouter'; diff --git a/plugins/catalog-backend/src/service/types.ts b/plugins/catalog-backend/src/service/types.ts new file mode 100644 index 0000000000..eedc688bb3 --- /dev/null +++ b/plugins/catalog-backend/src/service/types.ts @@ -0,0 +1,49 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Entity, LocationSpec, Location } from '@backstage/catalog-model'; + +export interface LocationService { + createLocation( + spec: LocationSpec, + dryRun: boolean, + ): Promise<{ location: Location; entities: Entity[]; exists?: boolean }>; + listLocations(): Promise; + getLocation(id: string): Promise; + deleteLocation(id: string): Promise; +} + +/** + * Options for requesting a refresh of entities in the catalog. + * + * @public + */ +export type RefreshOptions = { + /** The reference to a single entity that should be refreshed */ + entityRef: string; +}; + +/** + * A service that manages refreshes of entities in the catalog. + * + * @public + */ +export interface RefreshService { + /** + * Request a refresh of entities in the catalog. + */ + refresh(options: RefreshOptions): Promise; +}