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

prisma-schema-forge

v0.1.4

Published

Forge multiple artifacts from your Prisma schema models

Downloads

32

Readme

prisma-schema-forge

GitHub license

prisma-schema-forge is a tool that uses a template engine to generate code and files based on your Prisma schema. It can be easily installed using the npx command, and you can customize templates to generate files efficiently.

Overview

This tool generates various files using specified template files based on the definitions in schema.prisma. For example, it can be used to generate GraphQL queries, mutations, or ValueObject classes.

Installation

npx prisma-schema-forge

This package can be directly used with the npx command, and no special installation is required.

Commands

You can use the following commands to generate template files or custom files.

init

Initializes the forge.json configuration file.

npx prisma-schema-forge init

Running this command will generate the forge.json configuration file and automatically prepare the setup.

templates

Generates sample templates.

npx prisma-schema-forge templates

This command will copy the required template files into the ./templates folder in your project. You can then customize these templates as needed.

generate

Generates files based on schema.prisma and the template files.

npx prisma-schema-forge generate

This command generates files according to the forge.json configuration file. If you want to use a custom configuration file, you can specify it using the -c option.

npx prisma-schema-forge generate -c custom-forge.json

Template Engine

prisma-schema-forge uses a template engine to generate files. You can dynamically insert model and column names from the Prisma schema by using the following tokens.

Model Tokens

| Token | Description | Example | | ---------------------- | --------------------------------- | --------------------------- | | __model__ | Model name (singular, PascalCase) | SampleDummy | | __modelPlural__ | Model name (plural, PascalCase) | SampleDummies | | __modelCamel__ | Model name (singular, camelCase) | sampleDummy | | __modelCamelPlural__ | Model name (plural, camelCase) | sampleDummies | | __modelKebab__ | Model name (singular, kebab-case) | sample-dummy | | __modelKebabPlural__ | Model name (plural, kebab-case) | sample-dummies | | __modelColumns__ | List of model columns | idnamemessage |

Column Tokens

| Token | Description | Example | | ----------------- | ---------------------------------- | ------------------------------ | | __column__ | Column name (original, PascalCase) | UserId | | __columnCamel__ | Column name (camelCase) | userId | | __columnKebab__ | Column name (kebab-case) | user-id | | __columnType__ | Column type (TypeScript type) | stringnumberDate |

Template File Names and Folder Structure

Model-based File Generation

Based on the template folder structure, folders and files corresponding to each Prisma model are generated. Files with .txt extensions in the templates will have .txt removed when generated.

Example Template Structure:

templates/
  graphql/
    __modelKebab__.graphql.txt

Generated File Structure:

@generated/
  dummy-sample/
    graphql/dummy-sample.graphql
  dummy-user/
    graphql/dummy-user.graphql

Here, __modelKebab__ is replaced with the model name in kebab-case, such as dummy-sample or dummy-user.

Column-based File Generation

Files corresponding to columns are generated with folders named according to each column name, replacing the $column placeholder in the template.

Example Template Structure:

templates/
  value-objects/
    $column/
      __columnKebab__.ts.txt

Generated File Structure:

@generated/
  dummy-sample/
    value-objects/
      created-at/created-at.ts
      float/float.ts
      id/id.ts
      int/int.ts
      text/text.ts
      updated-at/updated-at.ts

Here, the $column placeholder in the template is replaced by the actual column names, such as created-at, id, updated-at, and the corresponding files are generated.

Example Usage

Consider the following schema.prisma definition:

// ...
model DummySample {
    id        String   @id
    text      String?
    int       Int?
    float     Float?
    createdAt DateTime @default(now())
    updatedAt DateTime @default(now()) @updatedAt
}

GraphQL Generation

You can define GraphQL queries or mutations as follows:

Template:

query get__modelPlural__ {
  __modelCamelPlural__ {
    __modelColumns__
  }
}

Generated code (for the DummySample model):

query getDummySamples {
  dummySamples {
    id
    text
    int
    float
    createdAt
    updatedAt
  }
}

ValueObject Class Generation

Template:

import { ValueObject } from './abstractions/value-object';

export class __column__ extends ValueObject<__columnType__, '__column__'> {
  constructor(value: __columnType__) {
    super(value);
  }

  protected validate(value: __columnType__): void {
    // TODO: add validation logic...
  }
}

Generated code (for the id column):

import { ValueObject } from './abstractions/value-object';

export class Id extends ValueObject<string, 'Id'> {
  constructor(value: string) {
    super(value);
  }

  protected validate(value: string): void {
    // TODO: add validation logic...
  }
}

Configuration File (forge.json)

In the forge.json file, you can configure the types of files to generate, the paths of template files, and the output directory. Here's an example configuration:

{
  "prismaSchema": "./prisma/schema.prisma",
  "templates": "./templates",
  "output": "./@generated"
}

Contributing

  1. Fork this repository.
  2. Create a new branch and make your changes.
  3. Submit a pull request and request a review.

License

This project is licensed under the MIT License.