Files
clawdbot/src/cron/payload-migration.ts
Peter Steinberger 98d0318d4e refactor: cron payload migration cleanup (#621)
* refactor: centralize cron payload migration

* test: stabilize block streaming mocks

* test: adjust chunker fence-close case
2026-01-09 22:56:55 +00:00

39 lines
982 B
TypeScript

type UnknownRecord = Record<string, unknown>;
function readString(value: unknown): string | undefined {
if (typeof value !== "string") return undefined;
return value;
}
function normalizeProvider(value: string): string {
return value.trim().toLowerCase();
}
export function migrateLegacyCronPayload(payload: UnknownRecord): boolean {
let mutated = false;
const providerValue = readString(payload.provider);
const channelValue = readString(payload.channel);
const nextProvider =
typeof providerValue === "string" && providerValue.trim().length > 0
? normalizeProvider(providerValue)
: typeof channelValue === "string" && channelValue.trim().length > 0
? normalizeProvider(channelValue)
: "";
if (nextProvider) {
if (providerValue !== nextProvider) {
payload.provider = nextProvider;
mutated = true;
}
}
if ("channel" in payload) {
delete payload.channel;
mutated = true;
}
return mutated;
}