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