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

@mohammed-bahumaish/prisma-dmmf-modifier

v1.0.0

Published

A TypeScript library to programmatically modify Prisma's DMMF (Datamodel Meta Format)

Readme

Prisma DMMF Modifier

A TypeScript library designed to programmatically modify Prisma's DMMF (Datamodel Meta Format) - the internal representation of Prisma schema.

npm version License: MIT

Installation

# Using npm
npm install @prisma-editor/prisma-dmmf-modifier

# Using yarn
yarn add @prisma-editor/prisma-dmmf-modifier

# Using pnpm
pnpm add @prisma-editor/prisma-dmmf-modifier

Quick Start

import { DMMFModifier, AddModelCommand, AddFieldCommand } from '@prisma-editor/prisma-dmmf-modifier';

// Create a new modifier with initial datamodel
const modifier = new DMMFModifier(datamodel);

// Add a model
const addModelCommand = new AddModelCommand("User");
modifier.do(addModelCommand);

// Add a field to the model
const addFieldCommand = new AddFieldCommand("User", {
  name: "email",
  kind: "scalar",
  type: "String",
  isRequired: true,
  // other field properties...
});
modifier.do(addFieldCommand);

// Get the modified datamodel
const modifiedDatamodel = modifier.get();

// Undo the last operation
modifier.undo();

Architecture Documentation

Overview

The prisma-dmmf-modifier is a TypeScript library designed to programmatically modify Prisma's DMMF (Datamodel Meta Format) - the internal representation of Prisma schema. This library provides a structured way to manipulate Prisma schemas through code instead of directly editing schema files, enabling developers to:

  • Add, update, and remove models
  • Add, update, and remove fields from models
  • Add, update, and remove enums and enum values
  • Manage relations between models (one-to-one, one-to-many, many-to-many)

Core Architecture

The project follows a command pattern architecture with the following key components:

1. DMMF Modifier Core (dmmfModifier.ts)

The DMMFModifier class serves as the central coordinator for all schema modifications. It maintains:

  • The current state of the datamodel
  • A history of commands for undo functionality

All modifications go through this class, providing a consistent interface for schema changes.

2. Datamodel (datamodel.ts)

The Datamodel class encapsulates the actual DMMF structure and provides methods to directly modify it:

  • addModel, removeModel
  • addField, updateField, removeField
  • addEnum, removeEnum, addEnumField, updateEnumField, removeEnumField

This class contains the implementation details for each modification operation.

3. Command Pattern Implementation (commands/)

The library implements the Command pattern to enable operations and their reversals (undo):

  • Each command (like AddFieldCommand, RemoveModelCommand, etc.) extends the abstract DMMFCommand class
  • Commands have do() and undo() methods for executing and reversing operations
  • Commands are executed through the DMMFModifier.do() method and can be undone with DMMFModifier.undo()

Available commands:

  • Model operations: AddModelCommand, RemoveModelCommand
  • Field operations: AddFieldCommand, UpdateFieldCommand, RemoveFieldCommand
  • Enum operations: AddEnumCommand, RemoveEnumCommand
  • Enum field operations: AddEnumFieldCommand, UpdateEnumFieldCommand, RemoveEnumFieldCommand

4. Relation Management (relationManager/)

The RelationManager and its sub-modules handle the complex logic of creating and maintaining relationships between models:

  • RelationType abstractions for different relation types
  • Specialized handlers for each relation type: OneToOne, OneToMany, ManyToMany
  • Support for creating the necessary fields and foreign keys for each relation type

Directory Structure

src/
├── commands/                   # Command pattern implementations
│   ├── addFieldCommand.ts      # Add field to model
│   ├── addEnumCommand.ts       # Add enum
│   ├── removeFieldCommand.ts   # And other command implementations...
│   └── index.ts                # Exports all commands
├── relationManager/            # Relation handling
│   ├── index.ts                # Main RelationManager class
│   └── relationType/           # Specialized relation type handlers
│       ├── oneToOne.ts
│       ├── oneToMany.ts
│       ├── manyToMany.ts
│       └── relationType.ts     # Base relationType interface
├── datamodel.ts                # Core datamodel manipulation
├── dmmfModifier.ts             # Main modifier class implementing command pattern
├── helpers.ts                  # Utility functions
├── nativeTypesOptions.ts       # Prisma native type definitions
├── types.ts                    # Type definitions
└── index.ts                    # Public API exports

Technical Design

Command Pattern

The library uses the Command Pattern to:

  1. Encapsulate each schema modification as a separate object
  2. Track operation history for undo functionality
  3. Separate the modification logic from the actual execution

Type Safety

The library extensively uses TypeScript to ensure type safety:

  • Leverages Prisma's own type definitions from @prisma/generator-helper
  • Provides proper typing for DMMF structures and operations

Dependencies

The library depends on several Prisma packages:

  • @prisma/engine-core
  • @prisma/generator-helper
  • @prisma/internals

Build and Development

The project uses:

  • TypeScript for type-safe development
  • tsup for building (outputs both CommonJS and ESM modules)
  • Jest for testing
  • ESLint for code quality

Usage Patterns

The library is designed to be used as follows:

// Create a new modifier with initial datamodel
const modifier = new DMMFModifier(datamodel);

// Add a model
const addModelCommand = new AddModelCommand("User");
modifier.do(addModelCommand);

// Add a field to the model
const addFieldCommand = new AddFieldCommand("User", {
  name: "email",
  kind: "scalar",
  type: "String",
  isRequired: true,
  // other field properties...
});
modifier.do(addFieldCommand);

// Get the modified datamodel
const modifiedDatamodel = modifier.get();

// Undo the last operation
modifier.undo();