import { z } from 'zod' import { type Identity, Node, type NodeShape } from '../../types/index.ts' function identity(this: T) { return this.refine((v) => Node.isValid(v)).transform((v) => v as Identity) } function node(this: T) { return this.refine((v) => Node.isValid(v)).transform((v) => Node.from(v as NodeShape)) } z.ZodString.prototype.identity = identity z.ZodString.prototype.node = node // From https://github.com/colinhacks/zod/discussions/4445#discussioncomment-13236525 declare module 'zod' { interface ZodString { identity(): ReturnType> node(): ReturnType> } }