npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zod-path-proxy

v0.1.4

Published

Helpers for determining the path of a Zod error

Readme

zod-path-proxy

This library provides helpers for automatically resolving Zod paths based on the accessed object property. This is commonly required when doing complex superRefine operations through (deeply) nested objects. This library leans on using Proxy objects for determining the accessed properties and resolving it to a Zod path.

Installation

Install the package using your package manager of choice.

npm install zod-path-proxy       # npm
yarn add zod-path-proxy          # yarn
bun add zod-path-proxy           # bun
pnpm add zod-path-proxy          # pnpm

Usage

To use the library, two main functions are provided:

  • createZodPathObjectProxy: sets up a Proxy object which tracks the accessed properties.
  • getPropertyWithZodPath: retrieves a property from the proxy returned from createZodPathObjectProxy and returns a tuple containing the property value and Zod path.

Nested objects

The library correctly resolves the path when retrieving nested objects.

import { z } from "zod";

import {
  createZodPathObjectProxy,
  getPropertyWithZodPath,
} from "zod-path-proxy";

const schema = z
  .object({
    user: z.object({
      firstName: z.string(),
      lastName: z.string(),
      origin: z.object({
        country: z.string(),
        isForeigner: z.boolean(),
      }),
    }),
  })
  .superRefine((value, ctx) => {
    const proxy = createZodPathObjectProxy(value);

    const [country] = getPropertyWithZodPath(proxy.user.origin, "country");

    const [isForeigner, isForeignerPath] = getPropertyWithZodPath(
      proxy.user.origin,
      "isForeigner"
    );

    if (country === "Netherlands" && isForeigner) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: `User is not a foreigner when born in the Netherlands`,
        path: isForeignerPath,
      });
    }
  });

schema.parse({
  user: {
    firstName: "John",
    lastName: "Doe",
    origin: {
      country: "Netherlands",
      isForeigner: true,
    },
  },
});
/* [
    {
      "code": "custom",
      "path": [ "user", "origin", "isForeigner" ],
      "message": "User is not a foreigner when born in the Netherlands"
    }
] */

Nested arrays

Any regular object and/or array operations can be used in between, the proxy correctly propogates the Zod path in the result.

import { z } from "zod";

import {
  createZodPathObjectProxy,
  getPropertyWithZodPath,
} from "zod-path-proxy";

const schema = z
  .object({
    user: z.object({
      firstName: z.string(),
      lastName: z.string(),
      origin: z.object({
        country: z.string(),
        isForeigner: z.boolean(),
      }),
      hobbies: z.array(
        z.object({
          id: z.string(),
          label: z.string(),
        })
      ),
    }),
  })
  .superRefine((value, ctx) => {
    const proxy = createZodPathObjectProxy(value);

    const hobbies = proxy.user.hobbies;

    const disallowedHobby = hobbies.find((hobby) => hobby.id === "arson");

    if (disallowedHobby) {
      const [_disallowedHobbyId, disallowedHobbyIdPath] =
        getPropertyWithZodPath(disallowedHobby, "id");

      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: `Arson is a criminal act, not a hobby`,
        path: disallowedHobbyIdPath,
      });
    }
  });

schema.parse({
  user: {
    firstName: "John",
    lastName: "Doe",
    origin: {
      country: "Netherlands",
      isForeigner: true,
    },
    hobbies: [
      {
        id: "guitar",
        label: "Playing guitar",
      },
      {
        id: "arson",
        label: "Setting fire to buildings",
      },
    ],
  },
});
/* [
    {
      "code": "custom",
      "path": [ "user", "hobbies", 1, "id" ],
      "message": "Arson is a criminal act, not a hobby"
    }
] */