diff --git a/.changeset/many-swans-sort.md b/.changeset/many-swans-sort.md new file mode 100644 index 0000000000..fec613cf00 --- /dev/null +++ b/.changeset/many-swans-sort.md @@ -0,0 +1,10 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +**BREAKING**: + +- Removed the previously deprecated `runPeriodically` export. Please use the `@backstage/backend-tasks` package instead, or copy [the actual implementation](https://github.com/backstage/backstage/blob/02875d4d56708c60f86f6b0a5b3da82e24988354/plugins/catalog-backend/src/util/runPeriodically.ts#L29) into your own code if you explicitly do not want coordination of task runs across your worker nodes. +- Removed the previously deprecated `CatalogProcessorLocationResult.optional` field. Please set the corresponding `LocationSpec.presence` field to `'optional'` instead. +- Related to the previous point, the `processingResult.location` function no longer has a second boolean `optional` argument. Please set the corresponding `LocationSpec.presence` field to `'optional'` instead. +- Removed the previously deprecated `StaticLocationProcessor`. It has not been in use for some time; its functionality is covered by `ConfigLocationEntityProvider` instead. diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 0d9f306009..687f1029c5 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -333,7 +333,6 @@ export type CatalogProcessorErrorResult = { export type CatalogProcessorLocationResult = { type: 'location'; location: LocationSpec; - optional?: boolean; }; // @public @@ -812,7 +811,7 @@ function inputError( // @public @deprecated (undocumented) function location_2( newLocation: LocationSpec, - optional?: boolean, + _optional?: boolean, ): CatalogProcessorResult; // @public (undocumented) @@ -1007,10 +1006,7 @@ export const processingResult: Readonly<{ atLocation: LocationSpec, message: string, ) => CatalogProcessorResult; - readonly location: ( - newLocation: LocationSpec, - optional?: boolean | undefined, - ) => CatalogProcessorResult; + readonly location: (newLocation: LocationSpec) => CatalogProcessorResult; readonly entity: ( atLocation: LocationSpec, newEntity: Entity, @@ -1074,22 +1070,6 @@ export interface RouterOptions { refreshService?: RefreshService; } -// @public @deprecated -export function runPeriodically(fn: () => any, delayMs: number): () => void; - -// @public @deprecated (undocumented) -export class StaticLocationProcessor implements StaticLocationProcessor { - constructor(staticLocations: LocationSpec[]); - // (undocumented) - static fromConfig(config: Config): StaticLocationProcessor; - // (undocumented) - readLocation( - location: LocationSpec, - _optional: boolean, - emit: CatalogProcessorEmit, - ): Promise; -} - // @public (undocumented) export class UrlReaderProcessor implements CatalogProcessor { constructor(options: { reader: UrlReader; logger: Logger_2 }); diff --git a/plugins/catalog-backend/src/api/deprecatedResult.ts b/plugins/catalog-backend/src/api/deprecatedResult.ts index ecacc62c65..e616f3cf7d 100644 --- a/plugins/catalog-backend/src/api/deprecatedResult.ts +++ b/plugins/catalog-backend/src/api/deprecatedResult.ts @@ -68,9 +68,9 @@ export function generalError( */ export function location( newLocation: LocationSpec, - optional?: boolean, + _optional?: boolean, ): CatalogProcessorResult { - return { type: 'location', location: newLocation, optional }; + return { type: 'location', location: newLocation }; } /** diff --git a/plugins/catalog-backend/src/api/processingResult.ts b/plugins/catalog-backend/src/api/processingResult.ts index 5ad908dc8b..2fc2c9eac7 100644 --- a/plugins/catalog-backend/src/api/processingResult.ts +++ b/plugins/catalog-backend/src/api/processingResult.ts @@ -54,11 +54,8 @@ export const processingResult = Object.freeze({ return { type: 'error', location: atLocation, error: new Error(message) }; }, - location( - newLocation: LocationSpec, - optional?: boolean, - ): CatalogProcessorResult { - return { type: 'location', location: newLocation, optional }; + location(newLocation: LocationSpec): CatalogProcessorResult { + return { type: 'location', location: newLocation }; }, entity(atLocation: LocationSpec, newEntity: Entity): CatalogProcessorResult { diff --git a/plugins/catalog-backend/src/api/processor.ts b/plugins/catalog-backend/src/api/processor.ts index 12a008edc7..3f274d13ea 100644 --- a/plugins/catalog-backend/src/api/processor.ts +++ b/plugins/catalog-backend/src/api/processor.ts @@ -147,8 +147,6 @@ export type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void; export type CatalogProcessorLocationResult = { type: 'location'; location: LocationSpec; - /** @deprecated Set `location.presence = 'optional'` instead */ - optional?: boolean; }; /** @public */ diff --git a/plugins/catalog-backend/src/modules/core/StaticLocationProcessor.ts b/plugins/catalog-backend/src/modules/core/StaticLocationProcessor.ts deleted file mode 100644 index e22d011695..0000000000 --- a/plugins/catalog-backend/src/modules/core/StaticLocationProcessor.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2020 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 { Config } from '@backstage/config'; -import { - processingResult, - CatalogProcessorEmit, - LocationSpec, -} from '../../api'; - -/** - * @deprecated no longer in use, replaced by the ConfigLocationEntityProvider. - * @public - */ -export class StaticLocationProcessor implements StaticLocationProcessor { - static fromConfig(config: Config): StaticLocationProcessor { - const locations: LocationSpec[] = []; - - const lConfigs = config.getOptionalConfigArray('catalog.locations') ?? []; - for (const lConfig of lConfigs) { - const type = lConfig.getString('type'); - const target = lConfig.getString('target'); - locations.push({ type, target }); - } - - return new StaticLocationProcessor(locations); - } - - constructor(private readonly staticLocations: LocationSpec[]) {} - - async readLocation( - location: LocationSpec, - _optional: boolean, - emit: CatalogProcessorEmit, - ): Promise { - if (location.type !== 'bootstrap') { - return false; - } - - for (const staticLocation of this.staticLocations) { - emit(processingResult.location(staticLocation)); - } - - return true; - } -} diff --git a/plugins/catalog-backend/src/modules/core/index.ts b/plugins/catalog-backend/src/modules/core/index.ts index 9d582bfb34..364cede069 100644 --- a/plugins/catalog-backend/src/modules/core/index.ts +++ b/plugins/catalog-backend/src/modules/core/index.ts @@ -28,6 +28,5 @@ export type { PlaceholderResolverRead, PlaceholderResolverResolveUrl, } from './PlaceholderProcessor'; -export { StaticLocationProcessor } from './StaticLocationProcessor'; export { UrlReaderProcessor } from './UrlReaderProcessor'; export { parseEntityYaml } from '../util/parse'; diff --git a/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts b/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts index c3cc6e288b..ff12f2f3db 100644 --- a/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts +++ b/plugins/catalog-backend/src/processing/ProcessorOutputCollector.ts @@ -106,9 +106,8 @@ export class ProcessorOutputCollector { this.deferredEntities.push({ entity, locationKey: location }); } else if (i.type === 'location') { - const presence = i.optional ? 'optional' : 'required'; const entity = locationSpecToLocationEntity( - { presence, ...i.location }, + i.location, this.parentEntity, ); const locationKey = getEntityLocationRef(entity); diff --git a/plugins/catalog-backend/src/util/index.ts b/plugins/catalog-backend/src/util/index.ts index 13a9c84b0f..0b5a942e0c 100644 --- a/plugins/catalog-backend/src/util/index.ts +++ b/plugins/catalog-backend/src/util/index.ts @@ -14,5 +14,4 @@ * limitations under the License. */ -export * from './runPeriodically'; export * from './RecursivePartial'; diff --git a/plugins/catalog-backend/src/util/runPeriodically.ts b/plugins/catalog-backend/src/util/runPeriodically.ts deleted file mode 100644 index 361fb33b2f..0000000000 --- a/plugins/catalog-backend/src/util/runPeriodically.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 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. - */ - -/** - * Runs a function repeatedly, with a fixed wait between invocations. - * - * Supports async functions, and silently ignores exceptions and rejections. - * - * @param fn - The function to run. May return a Promise. - * @param delayMs - The delay between a completed function invocation and the - * next. - * @returns A function that, when called, stops the invocation loop. - * @deprecated use \@backstage/backend-tasks package instead. - * @public - */ -export function runPeriodically(fn: () => any, delayMs: number): () => void { - let cancel: () => void; - let cancelled = false; - const cancellationPromise = new Promise(resolve => { - cancel = () => { - resolve(); - cancelled = true; - }; - }); - - const startRefresh = async () => { - while (!cancelled) { - try { - await fn(); - } catch { - // ignore intentionally - } - - await Promise.race([ - new Promise(resolve => setTimeout(resolve, delayMs)), - cancellationPromise, - ]); - } - }; - startRefresh(); - - return cancel!; -}