import { z } from "zod"; import "ramda"; type TuplesFromObject = { [P in keyof T]: [P, T[P]] }[keyof T]; type GetKeyByValue = TuplesFromObject extends infer TT ? (TT extends [infer P, V] ? P : never) : never; /** * @fileoverview Mapping utils for Zod Runtime Plugin (remap) * @link https://stackoverflow.com/questions/55454125/typescript-remapping-object-properties-in-typesafe */ type Remap = { [P in NonNullable]: T[GetKeyByValue]; }; type Intact = { [K in Exclude]: T[K] }; /** The property we store the brand in */ declare const brandProperty: "x-brand"; declare module "zod/v4/core" { interface GlobalMeta { default?: unknown; examples?: unknown[]; [brandProperty]?: PropertyKey; } } /** * @fileoverview Zod Runtime Plugin * @see https://github.com/colinhacks/zod/blob/90efe7fa6135119224412c7081bd12ef0bccef26/plugin/effect/src/index.ts#L21-L31 * @desc This code modifies and extends zod's functionality immediately when importing the plugin. * @desc Enables .example() and .deprecated() on all schemas (ZodType) * @desc Enables .xBrand() on all schemas as an alternative to .brand() that doesn't conflict with Zod 4.4+ * @desc Enables .label() on ZodDefault * @desc Enables .remap() on ZodObject * @desc Stores the argument supplied to .xBrand() on all schemas (runtime distinguishable) * */ declare module "zod" { interface ZodType< out Output = unknown, out Input = unknown, out Internals extends z.core.$ZodTypeInternals = z.core.$ZodTypeInternals, > extends z.core.$ZodType { /** @desc Shorthand for .meta({ examples }) */ example(example: z.output): this; deprecated(): this; /** @desc Shorthand for .meta({ "x-brand": ... }) */ xBrand(brand?: PropertyKey): this; } interface ZodDefault extends z._ZodType>, z.core.$ZodDefault { /** @desc Shorthand for .meta({ default }) */ label(label: string): this; } interface ZodObject< out Shape extends z.core.$ZodShape = z.core.$ZodLooseShape, out Config extends z.core.$ZodObjectConfig = z.core.$strip, > extends z._ZodType>, z.core.$ZodObject { remap( mapping: U, ): z.ZodPipe< z.ZodPipe, // internal type simplified z.ZodObject & Intact, Config> >; remap( mapper: (subject: Shape) => U, ): z.ZodPipe, z.ZodObject>; } }