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

@fhir-dsl/runtime

v1.2.2

Published

Runtime execution layer for FHIR DSL queries with pagination and error handling

Readme

@fhir-dsl/runtime

Runtime execution layer for fhir-dsl queries — HTTP client, pagination, and error handling.

Install

npm install @fhir-dsl/runtime

Usage

FhirExecutor

Executes compiled queries against a FHIR server:

import { FhirExecutor } from "@fhir-dsl/runtime";

const executor = new FhirExecutor({
  baseUrl: "https://hapi.fhir.org/baseR4",
  auth: { type: "bearer", credentials: "your-token" },
});

const bundle = await executor.execute({
  method: "GET",
  path: "Patient",
  params: [{ name: "family", value: "Smith" }],
});

Pagination

Handle paginated FHIR Bundle responses:

import { FhirExecutor, paginate, fetchAllPages } from "@fhir-dsl/runtime";

const executor = new FhirExecutor({ baseUrl: "https://hapi.fhir.org/baseR4" });
const firstBundle = await executor.execute(query);

// Stream pages with an async generator
for await (const page of paginate(executor, firstBundle)) {
  console.log(`Processing ${page.length} resources`);
}

// Or collect all pages at once
const allResources = await fetchAllPages(executor, firstBundle);

Bundle Unwrapping

Parse a FHIR Bundle into typed primary and included resources:

import { unwrapBundle } from "@fhir-dsl/runtime";

const result = unwrapBundle<Patient, Practitioner>(bundle);
// result.data      — Patient[]
// result.included  — Practitioner[]
// result.total     — number | undefined
// result.hasNext   — boolean
// result.nextUrl   — string | undefined
// result.raw       — original Bundle

Error Handling

FhirError extends FhirDslError with kind: "runtime.fhir". The same payload is available on the instance fields, on error.context, and inside error.toJSON() for transport.

import { FhirError } from "@fhir-dsl/runtime";
import { isFhirDslError } from "@fhir-dsl/utils";

try {
  await executor.execute(query);
} catch (error) {
  if (isFhirDslError(error) && error.kind === "runtime.fhir") {
    console.error(error.context.status, error.context.statusText);
    for (const issue of error.context.issues) {
      console.error(issue.severity, issue.diagnostics);
    }
    // Transport-safe across MCP, logs, error trackers:
    sendToErrorTracker(error.toJSON());
    // Walks the ES2022 cause chain (e.g. fetch failures wrapped by FhirError):
    // formatErrorChain(error) → "FhirError: 503 Service Unavailable ← TypeError: fetch failed"
  }
}

Or skip the try/catch entirely with the Result toolkit:

import { tryAsync } from "@fhir-dsl/utils";
import { FhirError } from "@fhir-dsl/runtime";

const r = await tryAsync<unknown, FhirError>(() => executor.execute(query));
if (!r.ok) console.error(r.error.kind, r.error.context.issues);

Configuration

interface FhirClientConfig {
  baseUrl: string;
  auth?: { type: "bearer" | "basic"; credentials: string };
  headers?: Record<string, string>;
  fetch?: typeof globalThis.fetch; // custom fetch implementation
}

License

MIT