mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
refactor: dedupe record guards
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
asOptionalRecord,
|
||||
hasNonEmptyString as sharedHasNonEmptyString,
|
||||
isRecord as sharedIsRecord,
|
||||
normalizeOptionalString,
|
||||
readStringValue,
|
||||
} from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export function encodeQuery(params: Record<string, string | undefined>): string {
|
||||
@@ -16,15 +18,11 @@ export function encodeQuery(params: Record<string, string | undefined>): string
|
||||
return queryString ? `?${queryString}` : "";
|
||||
}
|
||||
|
||||
export function readString(value: unknown): string | undefined {
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
export const readString = readStringValue;
|
||||
|
||||
export const normalizeString = normalizeOptionalString;
|
||||
|
||||
export function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
export const isRecord = sharedIsRecord;
|
||||
|
||||
export const asRecord = asOptionalRecord;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isRecord } from "../../../src/utils.js";
|
||||
|
||||
export type JsonObject = Record<string, unknown>;
|
||||
|
||||
export type ExternalPluginCompatibility = {
|
||||
@@ -22,10 +24,6 @@ export const EXTERNAL_CODE_PLUGIN_REQUIRED_FIELD_PATHS = [
|
||||
"openclaw.build.openclawVersion",
|
||||
] as const;
|
||||
|
||||
function isRecord(value: unknown): value is JsonObject {
|
||||
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function getTrimmedString(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { isRecord } from "../src/utils.js";
|
||||
|
||||
function writeStdoutLine(message = ""): void {
|
||||
process.stdout.write(`${message}\n`);
|
||||
@@ -546,10 +547,6 @@ function extractResponseText(payload: OpenAIResponse): string {
|
||||
return chunks.join("\n").trim();
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
function fallbackCategory(issueText: string): "bug" | "enhancement" {
|
||||
const lower = issueText.toLowerCase();
|
||||
const bugSignals = [
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { validateMinHostVersion } from "../../src/plugins/min-host-version.ts";
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
import { isRecord } from "../../src/utils.js";
|
||||
|
||||
export type ExtensionPackageJson = {
|
||||
name?: string;
|
||||
|
||||
7
scripts/lib/record-shared.mjs
Normal file
7
scripts/lib/record-shared.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
export function isRecord(value) {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export function trimString(value) {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
}
|
||||
@@ -1,18 +1,11 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { isRecord, trimString } from "./lib/record-shared.mjs";
|
||||
import { writeTextFileIfChanged } from "./runtime-postbuild-shared.mjs";
|
||||
|
||||
export const OFFICIAL_CHANNEL_CATALOG_RELATIVE_PATH = "dist/channel-catalog.json";
|
||||
|
||||
function isRecord(value) {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function trimString(value) {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
}
|
||||
|
||||
function toCatalogInstall(value, packageName) {
|
||||
const install = isRecord(value) ? value : {};
|
||||
const npmSpec = trimString(install.npmSpec) || packageName;
|
||||
|
||||
Reference in New Issue
Block a user