{"version":3,"file":"union-schema-CLNIi1fk.mjs","names":[],"sources":["../src/util/union-schema.ts"],"sourcesContent":["import { IsUnion, type TObject, type TUnion } from \"typebox\";\n\n/**\n * What a union may hold: an object, or another union of the same — so unions compose. Grouping\n * variants and composing the groups (`T.Union([Electronic, Manual])`) is the natural way to build a\n * large union up, and TypeBox supports it: `T.Static` reads a nested union as one flat union of\n * objects, exactly as if it had been written flat.\n */\nexport type UnionMember = TObject | TUnion<UnionMember[]>;\n\n/** A union of object variants, at any nesting depth. */\nexport type UnionSchema = TUnion<UnionMember[]>;\n\n/**\n * Every object variant of a union schema, with nested unions flattened away — the type-level\n * counterpart to `flattenVariants`, for the helpers that walk `anyOf` on the type rather than the\n * value. Without it a nested member fails an `extends TObject` test and collapses to `never`,\n * silently dropping that whole branch's fields.\n */\nexport type UnionVariants<T> =\n  T extends TUnion<infer V> ? UnionVariants<V[number]> : T extends TObject ? T : never;\n\n/**\n * Every object variant in a union, with nested unions flattened away.\n *\n * TypeBox does *not* normalize nesting: `T.Union([A, T.Union([B, C])])` keeps two members in\n * `anyOf`, one of which is itself a union. So while the static type flattens to `A | B | C`, code\n * walking `anyOf` has to flatten too — reading `.properties` off a nested union finds nothing and\n * throws. `Value.Check` and `Value.Clean` already recurse, so once the variant list is flat the\n * nesting makes no difference anywhere.\n */\nexport function flattenVariants(schema: UnionSchema): TObject[] {\n  const variants: TObject[] = [];\n  const visit = (member: UnionMember): void => {\n    if (IsUnion(member)) for (const nested of member.anyOf) visit(nested);\n    else variants.push(member);\n  };\n  visit(schema);\n  return variants;\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,SAAgB,gBAAgB,QAAgC;CAC9D,MAAM,WAAsB,CAAC;CAC7B,MAAM,SAAS,WAA8B;EAC3C,IAAI,QAAQ,MAAM,GAAG,KAAK,MAAM,UAAU,OAAO,OAAO,MAAM,MAAM;OAC/D,SAAS,KAAK,MAAM;CAC3B;CACA,MAAM,MAAM;CACZ,OAAO;AACT"}