perf(config): trim web search config helper imports

This commit is contained in:
Vincent Koc
2026-04-08 08:49:26 +01:00
parent a385121475
commit 680c0f77cb
2 changed files with 48 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
import { describe, expect, it } from "vitest";
import { resolvePluginWebSearchConfig } from "./plugin-web-search-config.js";
describe("resolvePluginWebSearchConfig", () => {
it("returns the nested plugin webSearch object when present", () => {
expect(
resolvePluginWebSearchConfig(
{
plugins: {
entries: {
brave: {
config: {
webSearch: {
apiKey: "brave-key",
},
},
},
},
},
},
"brave",
),
).toEqual({
apiKey: "brave-key",
});
});
it("ignores non-record plugin config values", () => {
expect(
resolvePluginWebSearchConfig(
{
plugins: {
entries: {
brave: {
config: "nope",
},
},
},
},
"brave",
),
).toBeUndefined();
});
});

View File

@@ -1,5 +1,3 @@
import { isRecord } from "../utils.js";
type PluginWebSearchConfigCarrier = {
plugins?: {
entries?: Record<
@@ -11,6 +9,10 @@ type PluginWebSearchConfigCarrier = {
};
};
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
export function resolvePluginWebSearchConfig(
config: PluginWebSearchConfigCarrier | undefined,
pluginId: string,