UNPKG

@dfinity/zod-schemas

Version:

A collection of reusable Zod schemas and validators for common data patterns in ICP applications

30 lines (29 loc) 1.13 kB
import { Principal } from "@icp-sdk/core/principal"; import * as z from "zod"; /** * Zod schema to validate a string as a valid textual representation of a Principal. * * This schema checks if the provided string can be converted into a `Principal` instance. * If the conversion fails, validation will return an error message. * * @example * ```typescript * const result = PrincipalTextSchema.safeParse('aaaaa-aa'); * console.log(result.success); // true or false * ``` */ export declare const PrincipalTextSchema: z.ZodString; export type PrincipalText = z.infer<typeof PrincipalTextSchema>; /** * Zod schema to validate and transform a value into a `Principal` instance. * * This schema checks if the provided value is an instance or an object representing * a `Principal` and transforms it into a valid `Principal` instance. * * @example * ```typescript * const result = PrincipalSchema.safeParse(Principal.fromText('aaaaa-aa')); * console.log(result.success); // true or false * ``` */ export declare const PrincipalSchema: z.ZodPipe<z.ZodCustom<Principal, Principal>, z.ZodTransform<Principal, Principal>>;