mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 17:51:22 +00:00
refactor: dedupe extension string record helpers
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export function encodeQuery(params: Record<string, string | undefined>): string {
|
||||
const query = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
@@ -14,20 +16,13 @@ export function readString(value: unknown): string | undefined {
|
||||
return typeof value === "string" ? value : undefined;
|
||||
}
|
||||
|
||||
export function normalizeString(value: unknown): string | undefined {
|
||||
return readString(value)?.trim() || undefined;
|
||||
}
|
||||
export const normalizeString = normalizeOptionalString;
|
||||
|
||||
export function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
export function asRecord(value: unknown): Record<string, unknown> | undefined {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
return undefined;
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
export const asRecord = asOptionalRecord;
|
||||
|
||||
export function hasNonEmptyString(value: unknown): value is string {
|
||||
return typeof value === "string" && value.trim().length > 0;
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
|
||||
import { KeyedAsyncQueue } from "openclaw/plugin-sdk/core";
|
||||
import type { PinnedDispatcherPolicy } from "openclaw/plugin-sdk/infra-runtime";
|
||||
import { normalizeNullableString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import type { SsrFPolicy } from "../runtime-api.js";
|
||||
import { resolveMatrixRoomKeyBackupReadinessError } from "./backup-health.js";
|
||||
import { FileBackedMatrixSyncStore } from "./client/file-sync-store.js";
|
||||
@@ -173,10 +174,7 @@ async function loadMatrixCryptoRuntime(): Promise<MatrixCryptoRuntime> {
|
||||
return await matrixCryptoRuntimePromise;
|
||||
}
|
||||
|
||||
function normalizeOptionalString(value: string | null | undefined): string | null {
|
||||
const normalized = value?.trim();
|
||||
return normalized ? normalized : null;
|
||||
}
|
||||
const normalizeOptionalString = normalizeNullableString;
|
||||
|
||||
function isUnsupportedAuthenticatedMediaEndpointError(err: unknown): boolean {
|
||||
const statusCode = (err as { statusCode?: number })?.statusCode;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
export function asRecord(value: unknown): Record<string, unknown> | undefined {
|
||||
return typeof value === "object" && value !== null
|
||||
? (value as Record<string, unknown>)
|
||||
: undefined;
|
||||
}
|
||||
import { asOptionalObjectRecord } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export const asRecord = asOptionalObjectRecord;
|
||||
|
||||
export function readString(
|
||||
record: Record<string, unknown> | undefined,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { asNullableObjectRecord } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { normalizeShip } from "../targets.js";
|
||||
|
||||
// Cite types for message references
|
||||
@@ -181,9 +182,7 @@ export async function resolveAuthorizedMessageText(params: {
|
||||
return citedContent + rawText;
|
||||
}
|
||||
|
||||
export function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value && typeof value === "object" ? (value as Record<string, unknown>) : null;
|
||||
}
|
||||
export const asRecord = asNullableObjectRecord;
|
||||
|
||||
export function formatErrorMessage(error: unknown): string {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
|
||||
Reference in New Issue
Block a user