import { z } from "zod/mini" import { WidgetKeySchema } from "../../common/widgetKey" import type { WidgetKey } from "../../common/widgetKey" export const DocumentLegacySchema = z.pipe( z.record(z.string(), z.unknown()), z.transform((value) => { const documentLegacy: Record = {} for (const [widgetKey, widgetValue] of Object.entries(value)) { // Keep v3 behavior: invalid widget keys are dropped, but the document // decode still succeeds. Widget value validation happens later in // DocumentLegacyCodec via WidgetLegacyCodec. const result = WidgetKeySchema.safeParse(widgetKey) if (result.success) { documentLegacy[result.data] = widgetValue } } return documentLegacy }), ) export type DocumentLegacy = z.infer