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

@sanity/codegen

v8.1.0

Published

Codegen toolkit for Sanity.io

Readme

@sanity/codegen

Codegen toolkit for Sanity.io, used to generate Typescript types for a Sanity Schema & GROQ queries.

Typed client.fetch results

With overloadClientMethods enabled (the default), the generated file ends with a query type map that registers every query it found, so client.fetch(query) in @sanity/client, and sanityFetch({query}) in next-sanity, return the generated result type without a generic:

// Query TypeMap
declare global {
  interface SanityQueries {
    '*[_type == "post"]': PostsQueryResult
  }
}
// Lets @sanity/client releases that predate the global registry read it too
declare module '@sanity/client' {
  interface SanityQueries extends globalThis.SanityQueries {}
}

The two blocks serve different @sanity/client releases, and the same generated file works with all of them:

  • The declare global block is the registry. @sanity/client releases that know about it read it directly, and because it is a global interface rather than a module augmentation, it does not depend on module resolution: it is seen whether or not @sanity/client is a direct dependency of the project that holds the generated file, however many copies of the client are installed (a copy nested inside next-sanity reads the same registry), and from every entry point, @sanity/client/stega included.
  • The declare module '@sanity/client' block is a bridge for releases that only read the SanityQueries interface exported from @sanity/client, which is every release since 6.21.0. Interface merging unions the extends clauses of an interface's declarations, so the bridge makes that interface inherit the global registry. On releases that already inherit it, the bridge is a duplicate extends of the same type, which TypeScript accepts.

The bridge is the only line that resolves @sanity/client. When the client cannot be resolved from the generated file, TypeScript reports TS2664: Invalid module name in augmentation for it in a .ts file, while in a declaration file an augmentation whose module cannot be found is skipped silently. Pointing generates at a .d.ts path therefore keeps the file valid in such a layout, and the global registry still types the client that is installed.

The earlier output, a declare module '@sanity/client' block that carried the whole map, keeps working with every @sanity/client release that accepts the new one.