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

@stiviar/modeled-react

v1.0.5

Published

Declarative, type-safe API layer for frontend apps. Register your API once, get validated data, caching, and testable contracts everywhere

Downloads

939

Readme

@stiviar/modeled-react

[!WARNING] This package is experimental. The API is unstable and may change at any time, including breaking changes in minor and patch releases. Don't use it in production yet.

Suggestions and feedback are very welcome: [email protected]

A declarative, type-safe API layer for React. Register your API once — as a type, a URL, and a Zod schema — and get a fully typed data-fetching hook with built-in caching and runtime validation.

No codegen, no backend language restrictions, no manual any casting between fetch and component. Just describe the shape of what you're calling, and modeled-react handles the rest.

Install

npm i @stiviar/modeled-react

Usage

Define your models once — covering a simple list, a single resource by id, a filtered list, and an OData-style query:

// api.ts
import { register } from "@stiviar/modeled-react";
import { Todo, TodoSchema, Todos, TodosSchema } from "./types";

export const api = register<{
  todos: { type: Todos }; // simple endpoint — no params
  todo: { type: Todo; params: { id: string } }; // single resource, accessed by id
  todosByStatus: { type: Todos; params: { completed: boolean } }; // filtered list, plain query params
  todosOData: {
    type: Todos;
    params: { $filter?: string; $orderby?: string; $top?: number };
  }; // OData-style query
}>({
  todos: {
    url: "https://api.example.com/todos",
    schema: TodosSchema, // schema is type checked against the registered type - no mismatch possible
  },
  todo: {
    url: (p) => `https://api.example.com/todos/${p.id}`, // type of p: {id: string}
    schema: TodoSchema,
  },
  todosByStatus: {
    url: (p) => `https://api.example.com/todos?completed=${p.completed}`, // type of p: {completed: boolean}
    schema: TodosSchema,
  },
  todosOData: {
    url: (p) => {
      // type of p: { $filter?: string; $orderby?: string; $top?: number }
      const query = new URLSearchParams(
        Object.entries(p).map(([k, v]) => [k, String(v)]),
      );
      return `https://api.example.com/odata/todos?${query.toString()}`;
    },
    schema: TodosSchema,
  },
});

export const useData = api.useData;

Use it in a component:

// Component.tsx
import { useData } from "./api";

export function Component() {
  const { data: allTodos } = useData("todos");
  const { data: oneTodo } = useData("todo", { id: "42" });
  const { data: activeTodos } = useData("todosByStatus", { completed: false });
  const { data: topTodos } = useData("todosOData", {
    $filter: "completed eq false",
    $orderby: "createdAt desc",
    $top: 10,
  });

  return <div>{allTodos?.length} todos total</div>;
}

Types declared for a model flow through the whole codebase — hover data in your IDE and see the inferred type, with a compile-time error if your schema and type ever drift apart. Every response is also validated at runtime against the same schema, so a change on the backend fails loudly instead of silently breaking the UI.

Features

  • Full type safety, no manual casting
  • Runtime validation on every fetch
  • Built-in caching (TanStack Query under the hood)
  • Typed error handling

Testing

Swap the fetch implementation at registration time so components stay testable without a network:

export const api = register<TypeModel>(apiModel, {
  fetchFn: IS_DEV ? mockFetch : fetch,
});

API

  • useData(key, params?) — TanStack Query-backed fetch hook for a registered endpoint

Status & feedback

This project is in an early, experimental stage. Expect API changes, renamed exports, and missing features while it evolves.

Ideas, bug reports, and feedback are appreciated. Email [email protected].

License

MIT