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

@f0rr0/thrift-compact-protocol

v1.0.0

Published

A tiny, type-safe Facebook Thrift Compact Protocol codec.

Readme

thrift-compact-protocol

A tiny, type-safe codec for the Facebook Thrift Compact Protocol. It has no runtime dependencies beyond the type-only Standard Schema spec and works with Uint8Array in Bun, Node.js, browsers, and other modern JavaScript runtimes.

Install

Requires Node.js 22+ or Bun 1.3+. CI verifies Node.js 22 and 24; releases run on Node.js 24.

bun add @f0rr0/thrift-compact-protocol

Use

import { type Infer, t } from "@f0rr0/thrift-compact-protocol";

const user = t.struct({
  id: t.i64.field(1),
  name: t.string.field(2),
  active: t.bool.field(3),
  tags: t.set(t.string).field(4).optional(),
  scores: t.map(t.string, t.i32).field(5),
});

type User = Infer<typeof user>;

const value: User = {
  id: 42n,
  name: "Ada",
  active: true,
  scores: new Map([["math", 100]]),
};

const bytes: Uint8Array = user.encode(value);
const decoded: User = user.decode(bytes);

Every struct is also a Standard Schema whose input is Uint8Array and output is the inferred object:

const result = user["~standard"].validate(bytes);

Types

The schema DSL mirrors Thrift without inventing another type system:

  • Scalars: t.bool, t.byte, t.i16, t.i32, t.i64, t.float, t.double, t.string, t.binary
  • Containers: t.list(type), t.set(type), t.map(key, value)
  • Fields: type.field(id), type.field(id).optional()
  • Structs: t.struct({ ...fields })

Field IDs are stable wire identities: match the remote Thrift schema and keep IDs unchanged when reordering or renaming properties. Every type, including a reusable struct, supports .field(id). Calling .field(id) or .optional() creates a new field descriptor without changing the original. Optionality applies to the field, not to collection elements.

i64 uses bigint, binary uses Uint8Array, and maps and sets use JavaScript's native Map and Set. Unknown fields are skipped for forward compatibility. Missing required fields, wrong wire types, invalid UTF-8, truncated payloads, out-of-range integers, and excessive nesting throw ThriftError.

This package implements raw struct payloads in current Facebook compact (V2): doubles and floats are big-endian, and compact type 13 is a 32-bit float. Legacy V1/Apache little-endian doubles, RPC message envelopes and Apache Thrift's newer UUID use of type 13 are out of scope. Raw structs have no version header, so both peers must agree on the dialect.

Regression tests adapt FBThrift C++, Rust and Go cases and include fixed wire vectors. See upstream provenance and limitations.

Develop

mise install
bun install
hk install
bun run check