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

@farm-framework/type-sync

v0.1.0

Published

Type synchronization utility for FARM framework (standalone)

Readme

@farm/type-sync

Overview

@farm/type-sync provides automated TypeScript type generation and API client code for FARM applications. It extracts an OpenAPI schema from your FastAPI backend and generates strongly typed artifacts that keep your front‑end and back‑end in sync. The package can run incrementally, cache generated files, and watch for changes during development.

✅ Completed Implementation

Core Components

  1. OpenAPI Extractor (extractors/openapi.ts)

    • Pulls the OpenAPI schema from a running or temporary FastAPI server
    • Falls back to cached or static schemas when extraction fails
    • Supports retries, health checks and startup timeouts
  2. TypeSync Orchestrator (orchestrator.ts)

    • Coordinates the full sync cycle
    • Manages generators, caching and performance metrics
    • Runs generators in parallel when possible
  3. Generation Cache (cache.ts)

    • Stores generated artifacts keyed by schema hash
    • Supports compression, expiration and cache metrics
  4. Generators (generators/*)

    • TypeScriptGenerator – emits raw TypeScript types
    • APIClientGenerator – creates an axios based API client
    • ReactHookGenerator – builds typed React Query hooks
    • AIHookGenerator – optional hooks for AI endpoints
  5. TypeSync Watcher (watcher.ts)

    • Watches Python source files and regenerates types on change
    • Touches a timestamp file so the frontend dev server reloads
  6. Type Differ (type-sync.ts)

    • Detects changes between previously generated schemas
    • Provides simple diff utilities for debugging

Architecture

┌─────────────────────────────┐
│     TypeSync Orchestrator    │
├─────────────────────────────┤
│  ┌───────────────┐          │
│  │ OpenAPI       │          │
│  │ Extractor     │          │
│  └───────────────┘          │
│  ┌───────────────┐          │
│  │ Generation    │          │
│  │ Cache         │          │
│  └───────────────┘          │
│  ┌───────────────┐          │
│  │  Generators   │─ Types   │
│  │               │─ Client  │
│  │               │─ Hooks   │
│  │               │─ AIHooks │
│  └───────────────┘          │
│  ┌───────────────┐          │
│  │   Watcher     │          │
│  └───────────────┘          │
└─────────────────────────────┘

Features Implemented

✅ Schema Extraction

  • Uses running server or temporary Uvicorn instance
  • Supports caching and static files as fallback
  • Health checks and retry logic

✅ Artifact Generation

  • Emits TypeScript types, API client, React hooks and AI hooks
  • Parallel generation with configurable concurrency
  • Incremental generation by comparing file checksums

✅ Caching

  • Disk based cache with optional compression
  • Automatic cleanup of expired entries
  • Metrics for hit ratio and total size

✅ Watch Mode

  • Watches Python sources for changes
  • Regenerates artifacts and notifies the frontend

✅ Error Handling & Recovery

  • Graceful fallback to cached schema on failures
  • Detailed logging of extraction and generation stages

Usage

Programmatic API

import { TypeSyncOrchestrator } from '@farm/type-sync';

const orchestrator = new TypeSyncOrchestrator();
await orchestrator.initialize({
  apiUrl: 'http://localhost:8000',
  features: { client: true, hooks: true, streaming: true, aiHooks: false },
});

const result = await orchestrator.syncOnce();
console.log(`Generated ${result.filesGenerated} files`);

Watcher

const watcher = new TypeSyncWatcher(orchestrator);
await watcher.start();

Press Ctrl+C to stop watching.

Scripts

Run the provided npm scripts to build the package:

pnpm run build:bundle     # Build ESM/CJS bundles
pnpm run build:watch      # Build in watch mode
pnpm run type-check       # Run TypeScript type checker

Configuration Example

await orchestrator.initialize({
  apiUrl: 'http://localhost:8000',
  outputDir: 'generated/types',
  features: {
    client: true,
    hooks: true,
    streaming: true,
    aiHooks: true,
  },
  performance: {
    enableMonitoring: true,
    enableIncrementalGeneration: true,
    maxConcurrency: 4,
    cacheTimeout: 300000,
  },
  generators: {
    typescript: { exportStyle: 'named' },
    apiClient: { baseURL: 'http://localhost:8000' },
    reactHooks: { enableInfiniteQueries: true },
    aiHooks: { defaultProvider: 'ollama' },
  },
});

File Structure

packages/type-sync/
├── src/
│   ├── cache.ts                # Generation cache implementation
│   ├── orchestrator.ts         # Main orchestrator
│   ├── watcher.ts              # File watcher for dev mode
│   ├── type-sync.ts            # Type differ utilities
│   ├── extractors/
│   │   └── openapi.ts          # FastAPI OpenAPI extractor
│   ├── generators/
│   │   ├── typescript.ts       # TS type generator
│   │   ├── api-client.ts       # API client generator
│   │   ├── react-hooks.ts      # React hook generator
│   │   └── ai-hooks.ts         # AI hook generator
│   ├── utils/
│   │   └── fetchWithRetry.ts   # Helper for fetch with retries
│   └── types.ts                # Shared type definitions
├── tsup.config.ts              # Build configuration
├── tsconfig.json               # TypeScript config
├── package.json                # Package metadata
└── README.md                   # This guide

Integration

  • Used by the FARM CLI for farm sync-types
  • Works with the development server to regenerate types on the fly
  • Produced artifacts live in generated/ by default

Next Steps

Future improvements could include:

  1. Smarter schema diffing and selective regeneration
  2. Additional generators (e.g., Python client)
  3. Improved error messaging and IDE integration