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

@polygonlabs/zod-codecs

v1.1.0

Published

Zod v4 codecs for the wire formats JSON-on-the-wire services keep reinventing — int64 strings, unbounded big integers, decimal strings, and ISO datetimes — that decode into the right runtime type and round-trip back.

Readme

@polygonlabs/zod-codecs

Zod v4 codecs for the wire formats JSON-on-the-wire services keep reinventing.

JSON has no native int64, no unbounded big integer, no precision-preserving decimal, and no native Date. Services serialise these as strings and hope every consumer decodes them the same way. This package ships the four decode/encode pairs the team has been writing inline, with the wire-format validation and runtime-type validation declared together.

Install

pnpm add @polygonlabs/zod-codecs zod

zod is a peer dependency. Requires Zod v4.

Codecs

| Codec | Wire | Runtime | Use for | | --- | --- | --- | --- | | Int64Codec | digit-string | bigint, int64-bounded | values that exceed Number.MAX_SAFE_INTEGER but fit in 64 bits — block heights, monotonic IDs, fixed-width counters | | BigIntegerCodec | digit-string | bigint, unbounded | values that can exceed int64 — wei amounts, raw uint256 values | | DecimalStringCodec | decimal-number string | string (validated) | financial / on-chain decimals where IEEE-754 precision is unacceptable | | IsoDateCodec | ISO-8601 string | Date | datetimes — bare z.date() doesn't make sense on the JSON wire |

Usage

import { z } from 'zod';
import {
  BigIntegerCodec,
  DecimalStringCodec,
  Int64Codec,
  IsoDateCodec
} from '@polygonlabs/zod-codecs';

const Trade = z.object({
  id: Int64Codec,                    // sequence number — fits in int64
  amountWei: BigIntegerCodec,        // uint256 wei value — needs unbounded bigint
  feeBps: DecimalStringCodec,        // basis points with fractional precision
  executedAt: IsoDateCodec
});

const parsed = await Trade.parseAsync({
  id: '12345',
  amountWei: '12345678901234567890123456789',
  feeBps: '0.0025',
  executedAt: '2025-04-28T13:45:00Z'
});
// parsed.id          → 12345n
// parsed.amountWei   → 12345678901234567890123456789n
// parsed.feeBps      → '0.0025'
// parsed.executedAt  → Date instance

z.encode(schema, value) runs the encode side and produces the wire shape:

import { z } from 'zod';

await z.encode(Trade, parsed);
// → {
//     id: '12345',
//     amountWei: '12345678901234567890123456789',
//     feeBps: '0.0025',
//     executedAt: '2025-04-28T13:45:00.000Z'
//   }

OpenAPI metadata

Codecs ship without .openapi() metadata baked in. Description, x-go-type hints, and example values are caller-specific — chain them at the registration site.

In zod v4, ZodCodec is a sibling class of ZodType rather than a subclass, so extendZodWithOpenApi from @asteasolutions/zod-to-openapi (which patches only ZodType.prototype.openapi) doesn't reach codecs — chaining .openapi(...) on a codec throws TypeError: not a function. This package's ./openapi entry-point fixes that:

import { z } from 'zod';
import { extendZodAndCodecsWithOpenApi } from '@polygonlabs/zod-codecs/openapi';
import { Int64Codec } from '@polygonlabs/zod-codecs';

extendZodAndCodecsWithOpenApi(z);

const BlockNumber = Int64Codec.openapi({
  description: 'Block height — fits in int64.',
  'x-go-type': 'int64'
});

extendZodAndCodecsWithOpenApi is a drop-in replacement for extendZodWithOpenApi — it calls through to the upstream patch and additionally extends the same patch to ZodCodec.prototype, so codec fields and regular fields behave identically (description, example, param: { in, name } for parameter declarations, refId merging across chained calls). Idempotent — safe to call multiple times.

@asteasolutions/zod-to-openapi is an optional peer dependency: the ./openapi entry-point is the only thing in this package that imports it. Codec consumers that don't generate OpenAPI never need it installed.

Pairs naturally with @polygonlabs/zod-to-openapi-heyapi

@polygonlabs/zod-to-openapi-heyapi is the team's @hey-api/openapi-ts plugin that sources Zod schemas (with codecs) from a zod-to-openapi OpenAPIRegistry, so generated clients call the codecs at runtime and hand callers the runtime shapes (bigint, Date) directly. This codec package is the recommended companion when using that plugin.

It is not a hard requirement — these codecs work standalone in any Zod-on-the-wire context: server validation, tRPC, MCP tooling, queue payloads, anywhere a JSON document crosses a trust boundary.