refactor: dedupe package record guards

This commit is contained in:
Peter Steinberger
2026-04-07 00:23:25 +01:00
parent f96c753ed3
commit a685a7afc9
4 changed files with 6 additions and 16 deletions

View File

@@ -1,13 +1,11 @@
import { isRecord } from "openclaw/plugin-sdk/text-runtime";
type JsonRecord = Record<string, unknown>;
const LEGACY_PATH = "models.bedrockDiscovery";
const TARGET_PATH = "plugins.entries.amazon-bedrock.config.discovery";
const BLOCKED_OBJECT_KEYS = new Set(["__proto__", "prototype", "constructor"]);
function isRecord(value: unknown): value is JsonRecord {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function isBlockedObjectKey(key: string): boolean {
return BLOCKED_OBJECT_KEYS.has(key);
}

View File

@@ -1,3 +1,4 @@
import { isRecord } from "openclaw/plugin-sdk/text-runtime";
import { DIFF_INDICATORS, DIFF_LAYOUTS, DIFF_THEMES } from "./types.js";
import type { DiffViewerPayload } from "./types.js";
@@ -85,10 +86,6 @@ function isViewerOptions(value: unknown): boolean {
return true;
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
function includesValue<T extends readonly string[]>(values: T, value: unknown): value is T[number] {
return typeof value === "string" && values.includes(value as T[number]);
}

View File

@@ -1,6 +1,7 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { isRecord } from "openclaw/plugin-sdk/text-runtime";
const ELEVENLABS_API_KEY_ENV = "ELEVENLABS_API_KEY";
const PROFILE_CANDIDATES = [".profile", ".zprofile", ".zshrc", ".bashrc"] as const;
@@ -22,10 +23,6 @@ type ElevenLabsApiKeyDeps = {
export const ELEVENLABS_TALK_PROVIDER_ID = "elevenlabs";
export function isRecord(value: unknown): value is JsonRecord {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function getRecord(value: unknown): JsonRecord | null {
return isRecord(value) ? value : null;
}

View File

@@ -1,12 +1,10 @@
import { isRecord } from "openclaw/plugin-sdk/text-runtime";
type UnsupportedSecretRefConfigCandidate = {
path: string;
value: unknown;
};
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
export const unsupportedSecretRefSurfacePatterns = [
"channels.whatsapp.creds.json",
"channels.whatsapp.accounts.*.creds.json",