Merge pull request #30969 from drodil/processor_priority

feat(catalog): processor priority
This commit is contained in:
Fredrik Adelöw
2025-09-16 15:16:44 +02:00
committed by GitHub
6 changed files with 59 additions and 1 deletions
+6
View File
@@ -251,6 +251,12 @@ export interface Config {
* Whether the processor is enabled or not. Defaults to true.
*/
enabled?: boolean;
/**
* The priority of the processor, which is used to determine the order in which
* processors are run. The default priority is 20, and lower value means
* that the processor runs earlier.
*/
priority?: number;
};
};
};
@@ -727,7 +727,32 @@ export class CatalogBuilder {
this.checkMissingExternalProcessors(processors);
return this.filterProcessors(processors);
const filteredProcessors = this.filterProcessors(processors);
// Lastly sort the processors by priority. Config can override the
// priority of a processor to allow control of 3rd party processors.
filteredProcessors.sort((a, b) => {
const getProcessorPriority = (processor: CatalogProcessor) => {
try {
return (
config.getOptionalNumber(
`catalog.processors.${processor.getProcessorName()}.priority`,
) ??
processor.getPriority?.() ??
20
);
} catch (_) {
// In case the processor config is not an object, just return default priority
return 20;
}
};
const aPriority = getProcessorPriority(a);
const bPriority = getProcessorPriority(b);
return aPriority - bPriority;
});
return filteredProcessors;
}
private filterProcessors(processors: CatalogProcessor[]) {
+1
View File
@@ -60,6 +60,7 @@ export type CatalogProcessor = {
emit: CatalogProcessorEmit,
cache: CatalogProcessorCache,
): Promise<Entity>;
getPriority?(): number;
};
// @public
@@ -100,6 +100,14 @@ export type CatalogProcessor = {
emit: CatalogProcessorEmit,
cache: CatalogProcessorCache,
): Promise<Entity>;
/**
* Returns a processor priority, which is used to determine the order in which
* processors are run. The default priority is 20, and lower value means
* that the processor runs earlier.
* @returns A number representing the priority of the processor.
*/
getPriority?(): number;
};
/**