perf: slim msteams store imports

This commit is contained in:
Peter Steinberger
2026-04-23 21:04:11 +01:00
parent 058e6f588a
commit 6f74763f1d
2 changed files with 18 additions and 6 deletions

View File

@@ -1,5 +1,4 @@
import crypto from "node:crypto";
import { isRecord, readNestedString } from "./attachments/shared.js";
import { resolveMSTeamsStorePath } from "./storage.js";
import { readJsonFile, withFileLock, writeJsonFile } from "./store-fs.js";
@@ -48,6 +47,18 @@ const STORE_FILENAME = "msteams-polls.json";
const MAX_POLLS = 1000;
const POLL_TTL_MS = 30 * 24 * 60 * 60 * 1000;
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function normalizeOptionalString(value: unknown): string | undefined {
if (typeof value !== "string") {
return undefined;
}
const trimmed = value.trim();
return trimmed ? trimmed : undefined;
}
function normalizeChoiceValue(value: unknown): string | null {
if (typeof value === "string") {
const trimmed = value.trim();
@@ -87,6 +98,10 @@ function readNestedValue(value: unknown, keys: Array<string | number>): unknown
return current;
}
function readNestedString(value: unknown, keys: Array<string | number>): string | undefined {
return normalizeOptionalString(readNestedValue(value, keys));
}
export function extractMSTeamsPollVote(
activity: { value?: unknown } | undefined,
): MSTeamsPollVote | null {

View File

@@ -1,9 +1,6 @@
import fs from "node:fs";
import {
readJsonFileWithFallback,
withFileLock as withPathLock,
writeJsonFileAtomically,
} from "../runtime-api.js";
import { withFileLock as withPathLock } from "openclaw/plugin-sdk/file-lock";
import { readJsonFileWithFallback, writeJsonFileAtomically } from "openclaw/plugin-sdk/json-store";
const STORE_LOCK_OPTIONS = {
retries: {