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

@reasonhealth/fhir-ts-codegen

v1.0.4

Published

General-purpose FHIR StructureDefinition → TypeScript declarations + Zod schemas

Readme

@reasonhealth/fhir-ts-codegen

npm

General-purpose CLI and library that reads FHIR NPM packages and emits either TypeScript .d.ts declarations or Zod schemas. Works with any FHIR IG package, not just the core specification.

Requirements

CLI

Config-file mode

Point at a generate.config.ts to run multiple packages in one pass:

bun run src/cli.ts --config path/to/generate.config.ts

Single-shot mode

# TypeScript declarations
bun run src/cli.ts \
  --package hl7.fhir.r4.core \
  --package-version 4.0.1 \
  --fhir-version r4 \
  --emit typescript \
  --namespace fhir4 \
  --out ./r4.d.ts \
  --test-out ./tests/r4-tests.ts  # optional

# Zod schemas
bun run src/cli.ts \
  --package hl7.fhir.r4.core \
  --package-version 4.0.1 \
  --fhir-version r4 \
  --emit zod \
  --out ./r4-schemas.ts

| Flag | Description | |------|-------------| | --package | FHIR NPM package ID (e.g. hl7.fhir.r4.core) | | --package-version | Package version (e.g. 4.0.1) | | --fhir-version | One of r2 r3 r4 r4b r5 | | --emit | typescript or zod | | --out | Output file path | | --namespace | UMD namespace name (TypeScript emit only, e.g. fhir4) | | --test-out | DefinitelyTyped test file output path (TypeScript emit only) | | --config | Path to a generate.config.ts (replaces all other flags) |

Config file format

import type { GenerateConfig } from '@reasonhealth/fhir-ts-codegen'

const config: GenerateConfig = {
  entries: [
    {
      packageId: 'hl7.fhir.r4.core',
      packageVersion: '4.0.1',
      fhirVersion: 'r4',
      emit: 'typescript',
      namespace: 'fhir4',          // required for typescript emit
      outFile: './r4.d.ts',
      testOutFile: './test/r4-tests.ts',  // optional
    },
    {
      packageId: 'hl7.fhir.r4.core',
      packageVersion: '4.0.1',
      fhirVersion: 'r4',
      emit: 'zod',
      outFile: './src/r4.ts',
    },
  ],
  // optional: generates an index.d.ts with /// <reference> entries for typescript emits
  indexOutFile: './index.d.ts',
}

export default config

Package resolution

Packages are resolved in this order — no manual download needed in most cases:

  1. Project cache.fhir-cache/ in the working directory
  2. System cache~/.fhir/packages/ (populated by FHIR IG Publisher and other tools)
  3. Download — fetched from https://packages.fhir.org and stored in the project cache

Library API

import { generate } from '@reasonhealth/fhir-ts-codegen'

await generate({
  packageId: 'hl7.fhir.r4.core',
  packageVersion: '4.0.1',
  fhirVersion: 'r4',
  emit: 'zod',
  outFile: '/tmp/r4-schemas.ts',
})

IR types are also exported for building custom emitters:

import type { IrModel, IrInterface, IrField } from '@reasonhealth/fhir-ts-codegen'

Architecture

StructureDefinition JSON (from FHIR NPM package)
        │
        ▼
   src/parser/
   ─ Backbone hoisting      PatientContact extends BackboneElement
   ─ Choice types [x]       deceasedBoolean + deceasedDateTime
   ─ Inline enum resolution  ('male'|'female'|'other'|'unknown')
   ─ contentReference        → isLazy: true
        │
        ▼
   Intermediary Representation (src/ir.ts)
        │
        ├──▶ src/emitter/typescript.ts  → .d.ts declarations
        └──▶ src/emitter/zod.ts         → z.object() schemas

Development

bun run typecheck

Supported By

This project is proudly supported by Vermonster / ReasonHealth.