diff --git a/.changeset/remove-location-processor-read.md b/.changeset/remove-location-processor-read.md new file mode 100644 index 0000000000..78aea6d820 --- /dev/null +++ b/.changeset/remove-location-processor-read.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +Remove the `read` argument of `LocationProcessor.processEntity`. +Instead, pass the `UrlReader` into the constructor of your `LocationProcessor`. diff --git a/plugins/catalog-backend/src/ingestion/LocationReaders.ts b/plugins/catalog-backend/src/ingestion/LocationReaders.ts index 8cbaaa3e8e..87c75e21e5 100644 --- a/plugins/catalog-backend/src/ingestion/LocationReaders.ts +++ b/plugins/catalog-backend/src/ingestion/LocationReaders.ts @@ -251,12 +251,7 @@ export class LocationReaders implements LocationReader { for (const processor of this.processors) { if (processor.processEntity) { try { - current = await processor.processEntity( - current, - item.location, - emit, - this.readLocation.bind(this), - ); + current = await processor.processEntity(current, item.location, emit); } catch (e) { // Construct the name carefully, if we got validation errors we do // not want to crash here due to missing metadata or so @@ -294,40 +289,4 @@ export class LocationReaders implements LocationReader { } } } - - private async readLocation(location: LocationSpec): Promise { - let data: Buffer | undefined = undefined; - let error: Error | undefined = undefined; - - await this.handleLocation( - { - type: 'location', - location, - optional: false, - }, - output => { - if (output.type === 'error' && !error) { - error = output.error; - } else if (output.type === 'data') { - if (data) { - if (!error) { - error = new Error( - 'More than one piece of data loaded unexpectedly', - ); - } - } else { - data = output.data; - } - } - }, - ); - - if (error) { - throw error; - } else if (!data) { - throw new Error('No data loaded'); - } - - return data; - } } diff --git a/plugins/catalog-backend/src/ingestion/processors/types.ts b/plugins/catalog-backend/src/ingestion/processors/types.ts index 66359b328b..cd2c423423 100644 --- a/plugins/catalog-backend/src/ingestion/processors/types.ts +++ b/plugins/catalog-backend/src/ingestion/processors/types.ts @@ -58,7 +58,6 @@ export type LocationProcessor = { entity: Entity, location: LocationSpec, emit: LocationProcessorEmit, - read: LocationProcessorRead, ): Promise; /** @@ -109,5 +108,3 @@ export type LocationProcessorResult = | LocationProcessorDataResult | LocationProcessorEntityResult | LocationProcessorErrorResult; - -export type LocationProcessorRead = (location: LocationSpec) => Promise;