use entityRef instead of Entity

Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
Kiss Miklos
2022-06-22 18:53:38 +02:00
parent 2b1ab47a7a
commit b713a4c8dc
11 changed files with 35 additions and 24 deletions
@@ -66,7 +66,7 @@ export const processingResult = Object.freeze({
return { type: 'relation', relation: spec };
},
refresh(entity: Entity, key: String) {
return { type: 'refresh', entity, key };
refresh(entityRef: String, key: String): CatalogProcessorResult {
return { type: 'refresh', entityRef, key };
},
} as const);
+1 -1
View File
@@ -172,7 +172,7 @@ export type CatalogProcessorErrorResult = {
/** @public */
export type CatalogProcessorRefreshKeysResult = {
type: 'refresh';
entity: Entity;
entityRef: String;
key: String;
};
@@ -540,13 +540,13 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
options: RefreshKeyOptions,
): Promise<void> {
const tx = txOpaque as Knex.Transaction;
const { keys } = options;
const { refreshKeys } = options;
await Promise.all(
keys.map(k => {
refreshKeys.map(k => {
return tx<DbRefreshKeysRow>('refresh_keys')
.insert({
entity_ref: stringifyEntityRef(k.entity),
entity_ref: k.entityRef,
key: k.key,
})
.onConflict(['entity_ref', 'key'])
@@ -82,7 +82,7 @@ export type ReplaceUnprocessedEntitiesOptions =
};
export type RefreshKeyOptions = {
keys: { key: String; entity: Entity }[];
refreshKeys: { key: String; entityRef: String }[];
};
export type RefreshByKeyOptions = {
@@ -25,6 +25,7 @@ import {
LocationSpec,
processingResult,
} from '../../api';
import { stringifyEntityRef } from '@backstage/catalog-model';
const glob = promisify(g);
@@ -62,11 +63,12 @@ export class FileReaderProcessor implements CatalogProcessor {
})) {
emit(parseResult);
if (parseResult.type === 'entity') {
emit({
type: 'refresh',
key: path.normalize(fileMatch),
entity: parseResult.entity,
});
emit(
processingResult.refresh(
stringifyEntityRef(parseResult.entity),
path.normalize(fileMatch),
),
);
}
}
}
@@ -15,7 +15,7 @@
*/
import { UrlReader } from '@backstage/backend-common';
import { Entity } from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
import { JsonValue } from '@backstage/types';
import { ScmIntegrationRegistry } from '@backstage/integration';
import yaml from 'yaml';
@@ -23,6 +23,7 @@ import {
CatalogProcessor,
CatalogProcessorEmit,
LocationSpec,
processingResult,
} from '../../api';
/** @public */
@@ -107,7 +108,7 @@ export class PlaceholderProcessor implements CatalogProcessor {
const resolverKey = keys[0].substr(1);
const resolverValue = data[keys[0]];
emit({ type: 'refresh', key: resolverValue, entity });
const resolver = this.options.resolvers[resolverKey];
if (!resolver || typeof resolverValue !== 'string') {
// If there was no such placeholder resolver or if the value was not a
@@ -133,6 +134,8 @@ export class PlaceholderProcessor implements CatalogProcessor {
base,
});
emit(processingResult.refresh(stringifyEntityRef(entity), resolverValue));
return [
await resolver({
key: resolverKey,
@@ -15,7 +15,7 @@
*/
import { UrlReader } from '@backstage/backend-common';
import { Entity } from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
import { assertError } from '@backstage/errors';
import parseGitUrl from 'git-url-parse';
import limiterFactory from 'p-limit';
@@ -84,11 +84,12 @@ export class UrlReaderProcessor implements CatalogProcessor {
parseResults.push(parseResult);
emit(parseResult);
if (parseResult.type === 'entity') {
emit({
type: 'refresh',
key: item.url,
entity: parseResult.entity,
});
emit(
processingResult.refresh(
stringifyEntityRef(parseResult.entity),
item.url,
),
);
}
}
}
@@ -58,6 +58,7 @@ describe('DefaultCatalogProcessingEngine', () => {
errors: [],
deferredEntities: [],
state: {},
refreshKeys: [],
});
const engine = new DefaultCatalogProcessingEngine(
getVoidLogger(),
@@ -123,6 +124,7 @@ describe('DefaultCatalogProcessingEngine', () => {
errors: [],
deferredEntities: [],
state: {},
refreshKeys: [],
});
const engine = new DefaultCatalogProcessingEngine(
getVoidLogger(),
@@ -203,6 +205,7 @@ describe('DefaultCatalogProcessingEngine', () => {
errors: [],
deferredEntities: [],
state: {},
refreshKeys: [],
});
const engine = new DefaultCatalogProcessingEngine(
@@ -413,6 +416,7 @@ describe('DefaultCatalogProcessingEngine', () => {
errors: [],
deferredEntities: [],
state: {},
refreshKeys: [],
})
.mockResolvedValueOnce({
ok: true,
@@ -432,6 +436,7 @@ describe('DefaultCatalogProcessingEngine', () => {
errors: [],
deferredEntities: [],
state: {},
refreshKeys: [],
});
await engine.start();
@@ -125,7 +125,7 @@ export class DefaultCatalogProcessingEngine implements CatalogProcessingEngine {
if (result.ok) {
await this.processingDatabase.transaction(tx =>
this.processingDatabase.setRefreshKeys(tx, {
keys: result.refreshKeys,
refreshKeys: result.refreshKeys,
}),
);
@@ -40,7 +40,7 @@ export class ProcessorOutputCollector {
private readonly deferredEntities = new Array<DeferredEntity>();
private readonly refreshKeys = new Array<{
key: String;
entity: Entity;
entityRef: String;
}>();
private done = false;
@@ -122,7 +122,7 @@ export class ProcessorOutputCollector {
} else if (i.type === 'error') {
this.errors.push(i.error);
} else if (i.type === 'refresh') {
this.refreshKeys.push({ key: i.key, entity: i.entity });
this.refreshKeys.push({ key: i.key, entityRef: i.entityRef });
}
}
}
@@ -37,7 +37,7 @@ export type EntityProcessingResult =
completedEntity: Entity;
deferredEntities: DeferredEntity[];
relations: EntityRelationSpec[];
refreshKeys: { key: String; entity: Entity }[];
refreshKeys: { key: String; entityRef: String }[];
errors: Error[];
}
| {