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

@teliagen/vite-plugin

v0.4.2

Published

Vite plugin for the Teliagen framework

Readme

@teliagen/vite-plugin

Vite plugin for Teliagen client code generation.

npm version TypeScript Vite License: Apache-2.0

Overview

@teliagen/vite-plugin generates typed client code from Teliagen server metadata:

  • Automatic Generation – Generates on dev server start
  • Hot Reload – Regenerates on metadata changes
  • Typed Hooks – React hooks with full TypeScript inference
  • Multiple Sources – Connect to multiple backend services
  • Local & Remote – Read from local files or fetch from servers

Installation

npm install -D @teliagen/vite-plugin
# or
pnpm add -D @teliagen/vite-plugin

Quick Start

Local Backend (Monorepo)

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { teliagen } from '@teliagen/vite-plugin';

export default defineConfig({
  plugins: [
    react(),
    teliagen({
      name: 'main',
      mode: 'local',
      path: '../server'  // Path to backend project
    })
  ]
});

Remote Backend

// vite.config.ts
import { teliagen } from '@teliagen/vite-plugin';

export default defineConfig({
  plugins: [
    teliagen({
      name: 'api',
      mode: 'remote',
      url: 'http://localhost:3000',
      endpoint: '/teliagen/metadata'
    })
  ]
});

Configuration

interface TeliagenViteOptions {
  // Identity
  name?: string;              // Source name (default: 'main')
  
  // Mode
  mode?: 'local' | 'remote';  // How to fetch metadata
  
  // Local mode options
  path?: string;              // Path to backend project
  metadataPath?: string;      // Direct path to metadata.json
  
  // Remote mode options
  url?: string;               // Backend URL
  endpoint?: string;          // Metadata endpoint (default: '/teliagen/metadata')
  
  // Generation
  strategy?: 'physical' | 'virtual';  // Output strategy
  outputDir?: string;         // Output directory (default: '.teliagen-client')
  
  // Error handling
  optional?: boolean;         // Don't fail if source unavailable
}

Multiple Sources

Connect to multiple backend services:

// vite.config.ts
import { teliagen } from '@teliagen/vite-plugin';

export default defineConfig({
  plugins: [
    teliagen([
      {
        name: 'main',
        mode: 'local',
        path: '../main-server'
      },
      {
        name: 'auth',
        mode: 'remote',
        url: 'http://localhost:3001',
        optional: true  // Don't fail if auth server is down
      },
      {
        name: 'payments',
        mode: 'remote',
        url: process.env.PAYMENTS_API_URL,
        optional: true
      }
    ])
  ]
});

Generated Output

The plugin generates typed client code:

.teliagen-client/
├── main/
│   ├── index.ts              # Barrel exports
│   ├── hooks/
│   │   ├── useLogin.ts       # Typed React hook
│   │   ├── useRegister.ts
│   │   └── useListUsers.ts
│   ├── schemas/
│   │   ├── LoginInput.ts
│   │   └── UserOutput.ts
│   └── types/
│       └── index.ts
├── auth/
│   └── ...
└── payments/
    └── ...

Generated Hook Example

// .teliagen-client/main/hooks/useLogin.ts
import { useTeliagenAction } from '@teliagen/react';

export interface LoginInput {
  email: string;
  password: string;
}

export interface LoginOutput {
  user: {
    id: string;
    email: string;
    name?: string;
  };
  token: string;
}

export function useLogin() {
  return useTeliagenAction<LoginInput, LoginOutput>(
    'login',
    { module: 'auth', provider: 'AuthActions' }
  );
}

Using Generated Code

// Import generated hooks
import { useLogin, useListUsers, useCreateUser } from '.teliagen-client/main';

function LoginPage() {
  const login = useLogin();
  
  return (
    <button onClick={() => login.execute({ 
      email: '[email protected]', 
      password: 'secret' 
    })}>
      Login
    </button>
  );
}

function UserList() {
  const { data, isLoading } = useListUsers({ page: 1, limit: 10 });
  
  if (isLoading) return <p>Loading...</p>;
  
  return (
    <ul>
      {data?.users.map(user => (
        <li key={user.id}>{user.name}</li>
      ))}
    </ul>
  );
}

TypeScript Configuration

Add the generated directory to your tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      ".teliagen-client/*": ["./.teliagen-client/*"]
    }
  },
  "include": [
    "src",
    ".teliagen-client"
  ]
}

Strategies

Physical (Default)

Generates actual files on disk:

teliagen({
  strategy: 'physical',  // default
  outputDir: '.teliagen-client'
})

Pros:

  • IDE support out of the box
  • Can be committed to git
  • Works with any bundler

Cons:

  • Files on disk

Virtual

Uses Vite virtual modules (no files on disk):

teliagen({
  strategy: 'virtual'
})

Pros:

  • No generated files
  • Cleaner project structure

Cons:

  • Requires Vite
  • IDE may need additional config

Watch Mode

In development, the plugin watches for metadata changes:

// Local mode: Watches .teliagen/metadata.json
// When backend regenerates metadata, client code updates

// Remote mode: Manual refresh needed (restart dev server)

Environment-Based Config

// vite.config.ts
export default defineConfig(({ mode }) => ({
  plugins: [
    teliagen({
      name: 'api',
      mode: mode === 'development' ? 'local' : 'remote',
      path: mode === 'development' ? '../server' : undefined,
      url: mode === 'production' ? process.env.API_URL : undefined
    })
  ]
}));

Error Handling

teliagen({
  name: 'auth',
  mode: 'remote',
  url: 'http://auth-service:3001',
  optional: true  // Log warning instead of failing
})

When optional: true:

  • Missing local metadata: Skips silently
  • Unreachable remote: Logs warning, continues build
  • Useful for services that may be down during development

Integration with Backend

Your backend should expose metadata via ClientContractSync or ServerContractSync:

// teliagen.config.ts (backend)
import { defineConfig, ClientContractSync } from '@teliagen/commons';

export default defineConfig({
  features: [
    ClientContractSync({
      endpoint: '/teliagen/metadata',
      allowInProduction: false
    })
  ]
});

Requirements

  • Vite >= 5.0.0
  • Node.js >= 18.0.0

Related Packages

Documentation

For full documentation, visit docs.teliagen.org.

License

Apache-2.0