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

prisma2ts

v1.1.0

Published

CLI tool that converts Prisma schema files into TypeScript interface/type declarations with inline JSDoc comments

Readme

prisma2ts

npm version npm downloads npm downloads license

A CLI tool that converts Prisma schema files into TypeScript interface/type declarations with inline JSDoc comments.

Installation

npm install -g prisma2ts

Or run directly with npx:

npx prisma2ts --input schema.prisma

Usage

prisma2ts [options]

Options

  • -i, --input <path> - Input Prisma schema file or directory (default: schema.prisma)
  • -o, --output <path> - Output TypeScript file or directory (prints to stdout if not specified)
  • -r, --recursive - Recursively process all .prisma files in input directory
  • -c, --config <file> - Path to configuration file
  • --init-config - Create a sample configuration file
  • --no-docs - Disable JSDoc comment generation
  • --table - Print summary table of parsed models and enums
  • --json - Output JSON representation instead of TypeScript
  • -V, --version - Display version number
  • -h, --help - Display help information

Examples

Basic usage:

prisma2ts --input schema.prisma --output types.ts

Generate without JSDoc comments:

prisma2ts --input schema.prisma --no-docs

Show summary table:

prisma2ts --input schema.prisma --table

Output as JSON:

prisma2ts --input schema.prisma --json

Recursive directory processing:

# Process all .prisma files in a directory
prisma2ts --recursive --input ./schemas --output ./types

# Process with table summary
prisma2ts -r --input ./schemas --output ./types --table

Configuration file usage:

# Create a sample configuration file
prisma2ts --init-config

# Use configuration file for custom mappings
prisma2ts --config prisma2ts.config.json

# Use custom config file path
prisma2ts --config ./configs/my-config.json

Features

  • Single File Conversion: Convert individual Prisma schema files
  • Recursive Directory Processing: Process entire directories of .prisma files at once
  • Configuration File Support: Define custom input/output mappings with prisma2ts.config.json
  • Custom File Mappings: Map specific schema files to custom output locations and names
  • Enum Conversion: Converts Prisma enums to TypeScript union types
  • Model Conversion: Converts Prisma models to TypeScript interfaces
  • JSDoc Generation: Preserves // comments as JSDoc annotations
  • Type Mapping: Maps Prisma types to appropriate TypeScript types
  • JSON Support: Includes JsonValue type alias when needed
  • Clean Output: Strips generator/datasource blocks and block comments
  • Directory Structure Preservation: Maintains nested folder structure in output

Configuration File

For complex projects with multiple schema files, you can use a configuration file to define custom input/output mappings.

Creating a Configuration File

prisma2ts --init-config

This creates a prisma2ts.config.json file with the following structure:

{
  "mappings": [
    {
      "input": "schemas/user.prisma",
      "output": "types/UserTypes.ts",
      "options": {
        "docs": true
      }
    },
    {
      "input": "schemas/product.prisma", 
      "output": "types/ProductTypes.ts"
    },
    {
      "input": "schemas/**/*.prisma",
      "output": "types/generated/{{name}}.ts"
    }
  ],
  "options": {
    "docs": true,
    "json": false
  }
}

Configuration Options

  • mappings: Array of input/output file mappings

    • input: Path to input .prisma file (supports basic glob patterns)
    • output: Path to output file (supports template variables like {{name}})
    • options: Per-mapping options (overrides global options)
  • options: Global options for all mappings

    • docs: Enable/disable JSDoc generation (default: true)
    • json: Output JSON instead of TypeScript (default: false)

Template Variables

You can use template variables in output paths:

  • {{name}}: Base filename without extension
  • {{dir}}: Directory name containing the input file
  • {{path}}: Relative path from current directory

Type Mappings

| Prisma Type | TypeScript Type | | ----------- | --------------- | | String | string | | Int | number | | Float | number | | Boolean | boolean | | DateTime | Date | | Json | JsonValue | | BigInt | bigint | | Bytes | string |

Example

Input (schema.prisma):

enum Role {
  USER     // Standard user
  ADMIN    // Administrator
}

model User {
  id    String @id
  email String @unique
  name  String? // Display name
  role  Role    @default(USER)
}

Output (TypeScript):

export type Role =
  /** Standard user */
  | "USER"
  /** Administrator */
  | "ADMIN";

export interface User {
  id: string;
  email: string;
  /** Display name */
  name?: string | null;
  role: Role;
}

License

MIT