From b2f2276ccd091c86c36a26eea63fff9bb2f83e73 Mon Sep 17 00:00:00 2001 From: secustor Date: Mon, 19 Feb 2024 13:16:05 +0100 Subject: [PATCH] feat: move custom data parser to CatalogModel extension point Signed-off-by: secustor --- .changeset/polite-zoos-pay.md | 2 +- .../src/service/CatalogPlugin.ts | 33 ++++++++++--------- plugins/catalog-node/api-report-alpha.md | 3 +- plugins/catalog-node/src/extensions.ts | 7 +++- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.changeset/polite-zoos-pay.md b/.changeset/polite-zoos-pay.md index 1a6a0c69a7..9596d1356c 100644 --- a/.changeset/polite-zoos-pay.md +++ b/.changeset/polite-zoos-pay.md @@ -3,4 +3,4 @@ '@backstage/plugin-catalog-node': minor --- -Allow setting EntityDataParser using CatalogProcessingExtensionPoint +Allow setting EntityDataParser using CatalogModelExtensionPoint diff --git a/plugins/catalog-backend/src/service/CatalogPlugin.ts b/plugins/catalog-backend/src/service/CatalogPlugin.ts index 7f7d07e6c8..1b4a6fba51 100644 --- a/plugins/catalog-backend/src/service/CatalogPlugin.ts +++ b/plugins/catalog-backend/src/service/CatalogPlugin.ts @@ -49,7 +49,6 @@ class CatalogProcessingExtensionPointImpl unprocessedEntity: Entity; errors: Error[]; }) => Promise | void; - #entityDataParser?: CatalogProcessorParser; addProcessor( ...processors: Array> @@ -80,15 +79,6 @@ class CatalogProcessingExtensionPointImpl this.#onProcessingErrorHandler = handler; } - setEntityDataParser(parser: CatalogProcessorParser): void { - if (this.#entityDataParser) { - throw new Error( - 'Attempted to install second EntityDataParser. Only one can be set.', - ); - } - this.#entityDataParser = parser; - } - get processors() { return this.#processors; } @@ -104,10 +94,6 @@ class CatalogProcessingExtensionPointImpl get onProcessingErrorHandler() { return this.#onProcessingErrorHandler; } - - get entityDataParser() { - return this.#entityDataParser; - } } class CatalogAnalysisExtensionPointImpl @@ -152,6 +138,21 @@ class CatalogModelExtensionPointImpl implements CatalogModelExtensionPoint { get fieldValidators() { return this.#fieldValidators; } + + #entityDataParser?: CatalogProcessorParser; + + setEntityDataParser(parser: CatalogProcessorParser): void { + if (this.#entityDataParser) { + throw new Error( + 'Attempted to install second EntityDataParser. Only one can be set.', + ); + } + this.#entityDataParser = parser; + } + + get entityDataParser() { + return this.#entityDataParser; + } } /** @@ -221,8 +222,8 @@ export const catalogPlugin = createBackendPlugin({ builder.addProcessor(...processingExtensions.processors); builder.addEntityProvider(...processingExtensions.entityProviders); - if (processingExtensions.entityDataParser) { - builder.setEntityDataParser(processingExtensions.entityDataParser); + if (modelExtensions.entityDataParser) { + builder.setEntityDataParser(modelExtensions.entityDataParser); } Object.entries(processingExtensions.placeholderResolvers).forEach( diff --git a/plugins/catalog-node/api-report-alpha.md b/plugins/catalog-node/api-report-alpha.md index d92e1b12c4..17ad6e7c1e 100644 --- a/plugins/catalog-node/api-report-alpha.md +++ b/plugins/catalog-node/api-report-alpha.md @@ -28,6 +28,7 @@ export const catalogAnalysisExtensionPoint: ExtensionPoint): void; } @@ -71,8 +72,6 @@ export interface CatalogProcessingExtensionPoint { errors: Error[]; }) => Promise | void, ): void; - // (undocumented) - setEntityDataParser(parser: CatalogProcessorParser): void; } // @alpha (undocumented) diff --git a/plugins/catalog-node/src/extensions.ts b/plugins/catalog-node/src/extensions.ts index 5890349a95..09a7e1d894 100644 --- a/plugins/catalog-node/src/extensions.ts +++ b/plugins/catalog-node/src/extensions.ts @@ -38,7 +38,6 @@ export interface CatalogProcessingExtensionPoint { ...providers: Array> ): void; addPlaceholderResolver(key: string, resolver: PlaceholderResolver): void; - setEntityDataParser(parser: CatalogProcessorParser): void; setOnProcessingErrorHandler( handler: (event: { unprocessedEntity: Entity; @@ -57,6 +56,12 @@ export interface CatalogModelExtensionPoint { * @param validators - The (subset of) validators to set */ setFieldValidators(validators: Partial): void; + + /** + * Sets the entity data parser which is used to read raw data from locations + * @param parser - Parser which will used to extract entities from raw data + */ + setEntityDataParser(parser: CatalogProcessorParser): void; } /**