import { createEmptyPluginRegistry } from "./registry-empty.js"; import type { PluginRegistry } from "./registry-types.js"; import {
PLUGIN_REGISTRY_STATE,
type RegistryState,
type RegistrySurfaceState,
} from "./runtime-state.js";
function asPluginRegistry(registry: RegistryState["activeRegistry"]): PluginRegistry | null { return registry;
}
/** Pin the channel registry so that subsequent `setActivePluginRegistry` calls * do not replace the channel snapshot used by `getChannelPlugin`. Call at * gateway startup after the initial plugin load so that config-schema reads
* and other non-primary registry loads cannot evict channel plugins. */
export function pinActivePluginChannelRegistry(registry: PluginRegistry) {
installSurfaceRegistry(state.channel, registry, true);
}
export function releasePinnedPluginChannelRegistry(registry?: PluginRegistry) { if (registry && state.channel.registry !== registry) { return;
}
installSurfaceRegistry(state.channel, state.activeRegistry, false);
}
/** Return the registry that should be used for channel plugin resolution. * When pinned, this returns the startup registry regardless of subsequent
* `setActivePluginRegistry` calls. */
export function getActivePluginChannelRegistry(): PluginRegistry | null { return asPluginRegistry(state.channel.registry ?? state.activeRegistry);
}
export function getActivePluginChannelRegistryVersion(): number { return state.channel.registry ? state.channel.version : state.activeVersion;
}
export function requireActivePluginChannelRegistry(): PluginRegistry { const existing = getActivePluginChannelRegistry(); if (existing) { return existing;
} const created = requireActivePluginRegistry();
installSurfaceRegistry(state.channel, created, false); return created;
}
export function getActivePluginRegistryKey(): string | null { return state.key;
}
export function getActivePluginRegistryVersion(): number { return state.activeVersion;
}
function collectLoadedPluginIds(
registry: PluginRegistry | null | undefined,
ids: Set<string>,
): void { if (!registry) { return;
} for (const plugin of registry.plugins) { if (plugin.status === "loaded" && plugin.format !== "bundle") {
ids.add(plugin.id);
}
}
}
/** * Returns plugin ids that were imported by plugin runtime or registry loading in * the current process. * * This is a process-level view, not a fresh import trace: cached registry reuse * still counts because the plugin code was loaded earlier in this process. * Explicit loader import tracking covers plugins that were imported but later * ended in an error state during registration. * Bundle-format plugins are excluded because they can be "loaded" from metadata * without importing any JS entrypoint.
*/
export function listImportedRuntimePluginIds(): string[] { const imported = new Set(state.importedPluginIds);
collectLoadedPluginIds(asPluginRegistry(state.activeRegistry), imported);
collectLoadedPluginIds(asPluginRegistry(state.channel.registry), imported);
collectLoadedPluginIds(asPluginRegistry(state.httpRoute.registry), imported); return [...imported].toSorted((left, right) => left.localeCompare(right));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.