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

@ts-pf/codegen

v0.1.5

Published

Opt-in .d.ts codegen from catalog() for split-repo createClient

Readme

@ts-pf/codegen

Print a nested Contract .d.ts from a @ts-pf/docs catalog(). The frontend uses today's createClient<Contract>(link) — no second runtime, no as typeof contract, no tsc --dts of the backend.

Agent skill: skills/ts-pf-codegen/. Sync with npx skills experimental_sync -y. Runnable split-repo app: examples/codegen.

Types never come from fetch() or JSON.parse casts. The catalog is the spec; the .d.ts is the TypeScript contract.

import { catalog } from '@ts-pf/docs'
import { emit } from '@ts-pf/codegen'
import { writeFileSync } from 'node:fs'

const spec = catalog(contract, { prefix: '/rpc' })
writeFileSync('catalog.json', JSON.stringify(spec, null, 2))
writeFileSync('contract.d.ts', emit(spec))
import { asResult, createClient } from '@ts-pf/client'
import { FetchLink } from '@ts-pf/client-http'
import type { Contract } from './contract.js'

const client = createClient<Contract>(new FetchLink({ url: '/rpc' }))
await client.planet.find({ id: 1 })

const result = await asResult(client.planet.find({ id: 1 }))
if (!result.ok && result.error.code === 'NOT_FOUND') {
  result.error.data.id
}

emit / catalogHash

import { emit, catalogHash, type EmitOptions } from '@ts-pf/codegen'

emit(catalog, {
  name: 'Contract', // default
  failOnUnavailable: false, // default; true throws on kind: 'unavailable'
  banner: true, // catalogVersion + sha256 hash
})

catalogHash(catalog) // 'sha256:<hex>' of canonical JSON

Generated procedures are ContractProcedure<I, O, E> with Phantom Standard Schema leaves so InferErrorData / asResult still narrow error.code === 'NOT_FOUND'. Protocol errors stay out of the generated error map (ClientError already unions them). No-input is void. Streams are AsyncIterable<Item>.

docs() on a procedure becomes JSDoc on that generated member (description, summary, @deprecated). Tags stay OpenAPI grouping; other .meta() keys are not printed. JSDoc is on Contract members — ContractClient is a mapped type, so hover on client.planet.find may not show it.

Runtime policy (cache vs write, auth, …) stays on the catalog. Ship catalog.json next to contract.d.ts and look up procedures[].meta by path. createClient<Contract> is still type-only.

The generated file uses import type { ContractProcedure } from '@ts-pf/contract'. This package does not import contract at runtime.

CLI

ts-pf-codegen emit <catalog.json|-> [-o contract.d.ts] [--name Contract] [--fail-on-unavailable]
ts-pf-codegen pull <url> [-o contract.d.ts] [--lock catalog.lock.json]
ts-pf-codegen hash <catalog.json|->

emit and hash read stdin when the path is -. Omit -o to write the .d.ts to stdout.

Commit contract.d.ts, or CI-run ts-pf-codegen pull and pin catalog.lock.json:

{
  "url": "https://api.example.com/catalog.json",
  "catalogVersion": 1,
  "catalogHash": "sha256:…"
}

Mismatch on pull exits non-zero. No registry in v1.

Serve the catalog in userland

Do not put this on FetchHandler. A GET under /rpc/... is a procedure miss / METHOD_NOT_ALLOWED, not a spec.

// Userland — not FetchHandler, not @ts-pf/codegen:
if (url.pathname === '/catalog.json') {
  return Response.json(catalog(contract, { prefix: '/rpc' }))
}
const result = await handler.handle(req, { prefix: '/rpc', context })

Not in this package

  • createClientFromCatalog
  • Folding into @ts-pf/client or @ts-pf/docs
  • OpenAPI-TS as the typed client (use @ts-pf/openapi for the polyglot export)
  • Type-level FromSchema over imported JSON
  • tsc --dts of the live router
  • Serving catalog from FetchHandler
  • Auth on pull (later)
  • A schema registry

The catalog is the portable spec. @ts-pf/openapi remains the polyglot OpenAPI 3.1 export.