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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tangrams

v0.15.0

Published

Code generation for the TanStack ecosystem

Readme

tangrams

Code generation for the TanStack ecosystem

npm version License: MIT pkg.pr.new

[!WARNING] This project is in alpha and under active development. APIs may change without notice.

Overview

tangrams is a comprehensive code generation tool for the TanStack ecosystem. It takes your GraphQL or OpenAPI schema and generates fully typed, ready-to-use artifacts for TanStack libraries.

Features

  • TanStack Query - Generate type-safe queryOptions, infiniteQueryOptions, and mutationOptions
  • TanStack Form - Generate type-safe formOptions with validation schemas
  • TanStack DB - Generate queryCollectionOptions with auto-detected CRUD operations

Supported Data Sources

  • GraphQL - Via introspection endpoint or local SDL files
  • OpenAPI - Via spec file (local or remote URL)

Installation

# bun
bun add -D tangrams

# npm
npm install -D tangrams

# pnpm
pnpm add -D tangrams

Peer Dependencies

Install dependencies based on what you're generating:

# TanStack Query (generates includes "query")
bun add @tanstack/react-query

# TanStack Form (generates includes "form")
bun add @tanstack/react-form

# TanStack DB (generates includes "db")
bun add @tanstack/react-db @tanstack/query-db-collection @tanstack/react-query

# Validation library (choose one - zod is the default)
bun add zod        # Default validator
# bun add valibot  # Lightweight alternative
# bun add arktype  # Type-first validation
# bun add effect   # Effect ecosystem

# GraphQL sources
bun add graphql-request

# OpenAPI sources
bun add @better-fetch/fetch

Quick Start

  1. Initialize configuration

    bunx tangrams init
  2. Configure your source in tangrams.config.ts:

    import { defineConfig } from "tangrams";
    
    export default defineConfig({
      sources: [
        {
          name: "api",
          type: "graphql",
          schema: { url: "http://localhost:4000/graphql" },
          documents: "./src/graphql/**/*.graphql",
          generates: ["query", "form"],
        },
      ],
    });
  3. Generate code

    bunx tangrams generate
  4. Use the generated code

    import { useQuery, useMutation } from "@tanstack/react-query"
    import { getUserQueryOptions, createUserMutationOptions } from "./tangrams/api/query/operations"
    
    function UserProfile({ userId }: { userId: string }) {
      const { data } = useQuery(getUserQueryOptions({ id: userId }))
      const { mutate } = useMutation(createUserMutationOptions())
    
      return <div>{data?.user?.name}</div>
    }

Vite Plugin

For Vite projects, tangrams provides a plugin that integrates code generation into your dev server and build process. The plugin reads configuration from your tangrams.config.ts file and provides automatic file watching and cleanup.

// vite.config.ts
import { defineConfig } from "vite"
import { tangrams } from "tangrams/vite"

export default defineConfig({
  plugins: [
    tangrams(), // Loads tangrams.config.ts automatically
  ],
})

Plugin Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | configFile | string | - | Path to config file (auto-discovers tangrams.config.ts by default) | | force | boolean | false | Force regenerate all files | | watch | boolean | true | Watch for changes in dev mode | | clean | boolean | true | Remove stale directories |

Custom Config Path

tangrams({ configFile: "./config/tangrams.config.ts" })

Documentation

For comprehensive documentation, configuration reference, and usage examples, visit the Tangrams Documentation.

  • Getting Started - Installation, configuration reference, and all available options
  • TanStack Query - Generate queryOptions, infiniteQueryOptions when applicable, and mutationOptions
  • TanStack Form - Generate formOptions with schema validation
  • TanStack DB - Generate collections with local-first data sync

CLI Reference

tangrams init

Initialize a new tangrams.config.ts file.

tangrams init [options]

Options:
  -f, --force    Overwrite existing config file

tangrams generate

Generate TypeScript code from your configured sources.

tangrams generate [options]

Options:
  -c, --config <path>    Path to config file
  -f, --force            Force regeneration of all files including client
  -w, --watch            Watch for file changes and regenerate
  --clean                Remove stale source directories from previous generations
  -y, --yes              Skip confirmation prompts (use with --clean)
  --env-file <path>      Path to env file (can be specified multiple times)
  --no-dotenv            Disable automatic .env file loading

Cleanup Mode

When using --clean, tangrams will detect and remove stale source directories from previous generations. This is useful when you rename or remove sources from your configuration.

# Remove stale artifacts (prompts for confirmation)
tangrams generate --clean

# Remove stale artifacts without prompting
tangrams generate --clean --yes

If tangrams detects that a source was renamed (same schema/spec, different name), it will automatically copy the client.ts file to the new source directory before removing the old one. This preserves any customizations you've made to the client.

Watch Mode

When using --watch, tangrams will:

  • Watch your config file, GraphQL documents, and OpenAPI specs for changes
  • Cache schemas between file changes for faster rebuilds
  • Continue watching even if generation fails

Interactive commands in watch mode:

  • Press r to force a full refresh (re-fetches all schemas)
  • Press q to quit

Roadmap

  • Multi-Framework Code Generation
  • TanStack DB - Electic Collections
  • TanStack DB - LocalStorage Collections
  • TBD

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © hobbescodes