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

@zodapi/core

v0.4.0

Published

Shared contract types, fixed validation-error shape, and typed error guards for zodapi

Readme

@zodapi/core

Shared foundation of zodapi: contract types, the fixed ValidationError 400 shape, typed error classes + guards, and the queryArray helper. No HTTP dependencies — servers, clients, and generated contracts all build on this.

Contract types

RouteDef is the structural shape of a route definition — createRoute() from @hono/zod-openapi (and route() from @zodapi/hono) produce objects satisfying it, so contracts can be shared with @zodapi/client without importing hono:

interface RouteDef {
  method: Method // 'get' | 'post' | ...
  path: string // '/users/{id}'
  alias?: string // zodios-style client method name
  request?: { params?; query?; headers?; cookies?; body? }
  responses: Record<string | number, { description?; content? }>
}

Type helpers derive everything a typed client needs from a route: SuccessData (union of 2xx json bodies), ErrorVariant (discriminated union of declared non-2xx responses as { status, data }), JsonBodySchema, AliasOf, RouteByAlias, and more. Runtime helpers jsonSchemaOfResponse and responseDefForStatus resolve response definitions (honouring 4XX ranges and default).

The fixed validation-error shape

Every zodapi server responds to request-validation failures with 400 as an RFC 9457 problem (Content-Type: application/problem+json), discriminated by its type URI and carrying the zod issues and failing request target as extension members. Documented as the ValidationError OpenAPI component:

{
  "type": "urn:zodapi:validation",
  "status": 400,
  "target": "query",
  "issues": [ ... zod issues ... ]
}

ValidationError (the zod schema), ProblemDetails (the generic RFC 9457 shape), validationErrorBody(target, zodError), isValidationErrorBody(data), PROBLEM_JSON_CONTENT_TYPE, and ZODAPI_VALIDATION_TYPE live here.

Errors and guards

The client throws typed errors; the guards narrow them against a route's declared responses (bodies are runtime-checked with zod):

  • ApiError — declared non-2xx response; UnexpectedResponseApiError — undeclared status; RequestValidationError / ResponseValidationError — client-side validation failures.
  • ValidationApiError — a decoded server-side validation failure. Its error is a real z.ZodError revived from the server's issues, so z.flattenError / z.treeifyError and existing form-mapping code handle server and client failures identically; target says which request part failed when known.
  • ProblemApiError — a decoded non-validation problem+json response; problem is the parsed RFC 9457 body, extension members included.
  • isErrorFromRoute(route, err) / isErrorFromAlias(routes, alias, err) — narrow to the route's declared error union (zodios isErrorFromPath / isErrorFromAlias equivalents).
  • matchErrorByStatus(route, err, 409) — narrow to one declared status.
  • isValidationError(err) — the fixed 400 shape above.
  • isAxiosErrorFromRoute(route, err) — same narrowing on a raw AxiosError, for code using axios directly rather than the zodapi client.

Error decoders

Decoders turn recognised non-2xx responses into the typed errors above, keyed by media type first (the RFC 9457 way), so one client-side error path works against any backend:

  • zodapiValidationDecoder — zodapi's own 400 (type: urn:zodapi:validation); losslessly revives the zod issues. Registered by default in @zodapi/client.
  • problemDetails(options?) — foreign RFC 9457 backends (ASP.NET, Spring, ...). A ValidationProblemDetails-style errors map becomes a ValidationApiError (keys split into zod paths, keyCasing defaults to 'camel', $.-rooted JSON keys stripped via jsonPathKeys); other problems become ProblemApiError. contentTypes and sniff control detection.
  • decodersFor(problemFlavor, options?) — the right decoder list for a generated contract's problemFlavor (see @zodapi/codegen).

Query arrays

zodapi serialises query arrays as a[]=1&a[]=2. Declare them with queryArray(item) — it wraps a lone value into a one-element array before z.array(item), because Hono hands single-occurrence keys to the schema as a bare string.

Install

pnpm add @zodapi/core zod

See the zodapi monorepo for the full picture: @zodapi/hono (server), @zodapi/client (typed client), @zodapi/codegen (contracts from OpenAPI docs for non-TypeScript backends).