refactor(plugins): share empty registry factory

This commit is contained in:
Peter Steinberger
2026-02-15 16:43:33 +00:00
parent 9adcccadb1
commit 3783cd3850
2 changed files with 8 additions and 19 deletions

View File

@@ -1,22 +1,7 @@
import type { PluginRegistry } from "../../../plugins/registry.js";
import { createEmptyPluginRegistry, type PluginRegistry } from "../../../plugins/registry.js";
export const createTestRegistry = (overrides: Partial<PluginRegistry> = {}): PluginRegistry => {
const base: PluginRegistry = {
plugins: [],
tools: [],
hooks: [],
typedHooks: [],
channels: [],
providers: [],
gatewayHandlers: {},
httpHandlers: [],
httpRoutes: [],
cliRegistrars: [],
services: [],
commands: [],
diagnostics: [],
};
const merged = { ...base, ...overrides };
const merged = { ...createEmptyPluginRegistry(), ...overrides };
return {
...merged,
gatewayHandlers: merged.gatewayHandlers ?? {},

View File

@@ -143,8 +143,8 @@ export type PluginRegistryParams = {
runtime: PluginRuntime;
};
export function createPluginRegistry(registryParams: PluginRegistryParams) {
const registry: PluginRegistry = {
export function createEmptyPluginRegistry(): PluginRegistry {
return {
plugins: [],
tools: [],
hooks: [],
@@ -159,6 +159,10 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
commands: [],
diagnostics: [],
};
}
export function createPluginRegistry(registryParams: PluginRegistryParams) {
const registry = createEmptyPluginRegistry();
const coreGatewayMethods = new Set(Object.keys(registryParams.coreGatewayHandlers ?? {}));
const pushDiagnostic = (diag: PluginDiagnostic) => {