feat: remove LocationProcessor.processEntity

Instead, pass the `UrlReader` into the constructor of your `LocationProcessor`.
This commit is contained in:
Oliver Sand
2020-10-08 15:04:53 +02:00
parent d6db01be37
commit 49d70ccab1
3 changed files with 7 additions and 45 deletions
@@ -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`.
@@ -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<Buffer> {
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;
}
}
@@ -58,7 +58,6 @@ export type LocationProcessor = {
entity: Entity,
location: LocationSpec,
emit: LocationProcessorEmit,
read: LocationProcessorRead,
): Promise<Entity>;
/**
@@ -109,5 +108,3 @@ export type LocationProcessorResult =
| LocationProcessorDataResult
| LocationProcessorEntityResult
| LocationProcessorErrorResult;
export type LocationProcessorRead = (location: LocationSpec) => Promise<Buffer>;