import { DiscriminatedUnionIR, SchemaIR } from "../../types.js"; import { FastGen, SlowGen } from "../context.js"; //#region src/core/codegen/schemas/discriminated-union.d.ts /** One `discriminator value → option index` dispatch entry. */ type DiscriminatorCase = DiscriminatedUnionIR["cases"][number]; declare function slowDiscriminatedUnion(ir: SchemaIR & { type: "discriminatedUnion"; }, g: SlowGen): string; /** * Emit an O(1) switch-dispatch fast-check for a discriminated union — real * (`z.discriminatedUnion`) or one detected inside a plain `z.union` * (see {@link detectUnionDiscriminator}). Both share this so the detected case * inherits the size-gating and the per-case guard strip. * * `discSkipKey` tells each object option to drop its own type-guard and * discriminator re-check: the caller's guard (`typeof x==="object"&&…` below) * already proved object-ness, and the matched switch case has fixed the * discriminator value, so re-emitting either is pure redundancy the optimizer * only removes when it inlines this helper — which a union large enough to * matter won't. Routed through the normal `visit` so size-gated extraction * still bounds the switch (the strip survives into any hoisted helper); * non-object options ignore the hint and keep their own guard. * * Returns null if any option is fast-path-ineligible. */ declare function emitFastDiscriminatedSwitch(g: FastGen, discriminator: string, cases: readonly DiscriminatorCase[], options: readonly SchemaIR[]): string | null; declare function fastDiscriminatedUnion(ir: DiscriminatedUnionIR, g: FastGen): string | null; /** * Detect whether a plain (untagged) `z.union` is *structurally* a discriminated * union, so its fast path can use O(1) switch dispatch instead of probing every * arm. Returns the discriminator + dispatch table, or null to keep the * `||`-chain. * * Requires (proving the switch accepts exactly what the `||`-chain would): every * option is a plain object that pins one shared key to a REQUIRED literal * (`prop.type === "literal"` — an optional/non-literal key is rejected), and the * literal values are pairwise DISJOINT across options. Disjointness is the crux: * it guarantees at most one option can accept any given input, so dispatching to * that single option is equivalent to trying them all. Any value shared by two * options (ambiguous), a non-switchable value (`undefined`/`NaN`), or a * non-object option makes detection bail to the safe `||`-chain. * * The slow path is untouched: it keeps `z.union`'s sequential trial and its * `invalid_union` error shape, so failure output stays byte-identical to Zod. * The fast path and the build path both dispatch on the result — the build * path from two options up (`minOptions`), since its options are hosted calls * either way and a switch only ever replaces probes with one call; see * `buildUnion`. */ declare function detectUnionDiscriminator(options: readonly SchemaIR[], minOptions?: number): { discriminator: string; cases: DiscriminatorCase[]; } | null; //#endregion export { detectUnionDiscriminator, emitFastDiscriminatedSwitch, fastDiscriminatedUnion, slowDiscriminatedUnion }; //# sourceMappingURL=discriminated-union.d.ts.map