refactor: cron payload migration cleanup (#621)

* refactor: centralize cron payload migration

* test: stabilize block streaming mocks

* test: adjust chunker fence-close case
This commit is contained in:
Peter Steinberger
2026-01-09 22:56:55 +00:00
committed by GitHub
parent e3c340fd38
commit 98d0318d4e
7 changed files with 173 additions and 62 deletions

View File

@@ -0,0 +1,38 @@
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;
}