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

@ir-kit/fn-schema-loader

v0.1.1

Published

Type-safe reader for fn-schema bundles. Resolves $ref pointers, indexes signatures by id and named types by identity keyword. Zero runtime dependencies — works in any JS runtime that can read JSON.

Downloads

227

Readme

@ir-kit/fn-schema-loader

Type-safe reader over a fn-schema bundle. Generic over the bundle type so signature ids and definition names land as literal-typed unions.

Zero runtime dependencies — works in any JS runtime that can read JSON.

When to use it

You have a fn-schema bundle (produced by the CLI or programmatically — doesn't matter which) and want ergonomic access from your app:

  • server endpoints looking up schemas by id
  • frontend form builders resolving $ref pointers
  • canvas tools matching types nominally via findByIdentity

If you're loading the JSON in one place and reading it once, the helper is overkill — just JSON.parse it.

Install

pnpm add @ir-kit/fn-schema-loader

Producing a bundle

Pick whichever fits your build chain — both produce the same JSON:

Programmatically

import { extract } from "@ir-kit/fn-schema-typescript";
import { emit } from "@ir-kit/fn-schema-core";
import { writeFile } from "node:fs/promises";

const result = await extract({
  files: ["src/api/**/*.ts"],
  schema: { identity: "x-fn-schema-ts" },
});
await writeFile(
  "generated/schemas.json",
  emit.toBundle(result, { pretty: true }),
);
await writeFile(
  "generated/schemas.ts",
  emit.toBundleTypesModule(result, { jsonImport: "./schemas.json" }),
);

Via CLI

npx fn-schema extract 'src/api/**/*.ts' --bundle generated/schemas.json --bundle-types --pretty

The .ts wrapper next to schemas.json is what unlocks literal-typed lookups in the reader.

Reading

import { createReader } from "@ir-kit/fn-schema-loader";
import schemas from "./generated/schemas"; // the typed wrapper

const reader = createReader(schemas);

reader.get("createUser"); // ✅ typed
reader.get("createUserx"); // ❌ TS error
reader.has("listUsers"); // type predicate

reader.inputOf("createUser"); // resolved (top-level $ref chased)
reader.outputOf("createUser");
reader.resolveRef("#/definitions/User");

// canvas-style nominal-type matching (only when bundle was extracted with `identity`)
reader.findByIdentity("User", "x-fn-schema-ts");
// → [{ signatureId: "createUser", position: "output", schema: {...} }, ...]

API

interface Reader<T extends Bundle> {
  readonly bundle: T;
  get<K extends SignatureId<T>>(id: K): T["signatures"][K] | undefined;
  has<K extends string>(id: K): id is K & SignatureId<T>;
  resolve<K extends DefinitionName<T>>(
    name: K,
  ): T["definitions"][K] | undefined;
  resolveRef(ref: string): Record<string, unknown> | undefined;
  inputOf<K extends SignatureId<T>>(id: K): unknown;
  outputOf<K extends SignatureId<T>>(id: K): unknown;
  findByIdentity(name: string, identityKey?: string): Match[];
  listSignatures(): SignatureId<T>[];
  listDefinitions(): DefinitionName<T>[];
}

identityKey defaults to "x-fn-schema-ts".

Without the typed wrapper

Works on any plain object too — you just lose autocomplete:

import { readFileSync } from "node:fs";
import { createReader, type Bundle } from "@ir-kit/fn-schema-loader";

const raw = JSON.parse(readFileSync("./schemas.json", "utf-8")) as Bundle;
const reader = createReader(raw);

$ref resolution

inputOf / outputOf chase a single top-level $ref. Nested $refs inside the schema body are left intact — call resolveRef yourself if you need to chase further. Keeps the helper predictable; no cycle handling.