From 7cfcddd9aaf3828c854799e5cc3635abba2708cc Mon Sep 17 00:00:00 2001 From: secustor Date: Thu, 18 Jan 2024 00:00:44 +0100 Subject: [PATCH] feat: throw error if extensions point tries to set data parser multiple times Signed-off-by: secustor --- plugins/catalog-backend/src/service/CatalogPlugin.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/src/service/CatalogPlugin.ts b/plugins/catalog-backend/src/service/CatalogPlugin.ts index 10ca57d7e1..91d3fa0ecc 100644 --- a/plugins/catalog-backend/src/service/CatalogPlugin.ts +++ b/plugins/catalog-backend/src/service/CatalogPlugin.ts @@ -42,7 +42,7 @@ class CatalogProcessingExtensionPointImpl #processors = new Array(); #entityProviders = new Array(); #placeholderResolvers: Record = {}; - entityDataParser: CatalogProcessorParser = defaultEntityDataParser; + entityDataParser?: CatalogProcessorParser; addProcessor( ...processors: Array> @@ -65,6 +65,11 @@ class CatalogProcessingExtensionPointImpl } setEntityDataParser(parser: CatalogProcessorParser): void { + if (this.entityDataParser) { + throw new Error( + 'Attempted to install second EntityDataParser. Only one can be set.', + ); + } this.entityDataParser = parser; } @@ -171,7 +176,9 @@ export const catalogPlugin = createBackendPlugin({ }); builder.addProcessor(...processingExtensions.processors); builder.addEntityProvider(...processingExtensions.entityProviders); - builder.setEntityDataParser(processingExtensions.entityDataParser); + builder.setEntityDataParser( + processingExtensions.entityDataParser ?? defaultEntityDataParser, + ); Object.entries(processingExtensions.placeholderResolvers).forEach( ([key, resolver]) => builder.setPlaceholderResolver(key, resolver),