import { z } from "zod/mini" import { GroupItemLegacySchema, NestableAndGroupLegacySchema } from "./group" // Legacy (before 2020) export const LegacySliceLegacySchema = NestableAndGroupLegacySchema export type LegacySliceLegacy = z.infer // Composite (2020 to 2021) // Keep non-repeat values raw here: array-shaped legacy payloads are ambiguous until // `codec/slice.ts` resolves the field model and picks the right decoder. export const CompositeSliceLegacySchema = z.object({ "non-repeat": z.optional(z.record(z.string(), z.unknown())), repeat: z.optional(z.array(GroupItemLegacySchema)), }) export type CompositeSliceLegacy = z.infer // Shared (2021 to present) // Keep primary values raw here: array-shaped legacy payloads are ambiguous until // `codec/slice.ts` resolves the field model and picks the right decoder. export const SharedSliceLegacySchema = z.object({ variation: z.string(), primary: z.transform((value) => z.record(z.string(), z.unknown()).safeParse(value).data || {}), items: z.transform((value) => z.array(GroupItemLegacySchema).safeParse(value).data || []), }) export type SharedSliceLegacy = z.infer // All export const SliceLegacySchema: z.ZodMiniType = z.union([ LegacySliceLegacySchema, CompositeSliceLegacySchema, SharedSliceLegacySchema, ]) export type SliceLegacy = LegacySliceLegacy | CompositeSliceLegacy | SharedSliceLegacy