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

@hero-dynamic-form/prisma-inspector

v1.0.43

Published

Prisma entity inspector adapter for @hero-dynamic-form/core

Readme

@hero-dynamic-form/prisma-inspector

Prisma entity inspector adapter for @hero-dynamic-form/core. This package provides both a library for runtime entity inspection and a CLI tool for generating Prisma schemas from your PostgreSQL database.

Installation

npm install @hero-dynamic-form/prisma-inspector @hero-dynamic-form/core @prisma/client

CLI Usage

Generate Prisma schema from database

# List all tables
npx prisma-inspector generate

# Generate schema from table
npx prisma-inspector generate users --output ./prisma/schema.prisma

# Append to existing schema
npx prisma-inspector generate posts --append

# Overwrite existing file
npx prisma-inspector generate users --force

Options:

  • --output, -o <path> - Output file (default: ./prisma/schema.prisma)
  • --force, -f - Overwrite existing files
  • --append - Append to existing schema file
  • --env <path> - Path to .env file (default: .env)

Environment Variables

DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASS=postgres
DB_NAME=your_database

Library Usage

Method 1: Using Prisma DMMF (Recommended)

import { DynamicFormCore } from '@hero-dynamic-form/core';
import { PrismaEntityInspector } from '@hero-dynamic-form/prisma-inspector';
import { PrismaClient, Prisma } from '@prisma/client';

// Create inspector from Prisma DMMF (Data Model Meta Format)
const inspector = PrismaEntityInspector.fromDMMF(Prisma.dmmf);

const config = {
  entityInspector: inspector,
  resources: [
    {
      name: 'users',
      entity: 'User', // Prisma model name
    },
  ],
  // ... rest of config
};

const core = new DynamicFormCore(config);
await core.init();
await core.start();

Method 2: Manual Model Registration

import { PrismaEntityInspector } from '@hero-dynamic-form/prisma-inspector';

const inspector = new PrismaEntityInspector();

// Manually register model metadata
inspector.registerModel('User', {
  name: 'User',
  fields: [
    {
      name: 'id',
      type: 'Int',
      isRequired: true,
      isList: false,
      isId: true,
    },
    {
      name: 'email',
      type: 'String',
      isRequired: true,
      isList: false,
      isUnique: true,
    },
    {
      name: 'name',
      type: 'String',
      isRequired: false,
      isList: false,
    },
  ],
});

// Use inspector in config
const config = {
  entityInspector: inspector,
  // ...
};

Features

  • Extracts Prisma model metadata automatically from DMMF
  • Generates validation rules based on field types and constraints
  • Supports all Prisma field types:
    • String → text
    • Int → int
    • BigInt → bigint
    • Float → float
    • Decimal → decimal
    • Boolean → boolean
    • DateTime → timestamp
    • Json → json
    • Bytes → bytea
  • Supports field modifiers:
    • @id - Primary key detection
    • @unique - Unique constraint
    • @default - Default values
    • ? - Optional fields
    • [] - Array fields
  • Automatic validation for:
    • Required fields
    • Email format (by field name)
    • URL format (by field name)
    • Phone format (by field name)
    • Enum values
    • JSON validation
    • DateTime validation
    • Numeric ranges

Prisma Schema Example

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  posts     Post[]
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

enum Role {
  USER
  ADMIN
  MODERATOR
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String?
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  Int
}

Full Example

import { DynamicFormCore, defineConfig } from '@hero-dynamic-form/core';
import { PrismaEntityInspector } from '@hero-dynamic-form/prisma-inspector';
import { PrismaClient, Prisma } from '@prisma/client';

const prisma = new PrismaClient();
const inspector = PrismaEntityInspector.fromDMMF(Prisma.dmmf);

const config = defineConfig({
  dataSource: prisma, // Pass Prisma client as dataSource
  entityInspector: inspector,
  resources: [
    {
      name: 'users',
      entity: 'User',
      label: 'Users',
    },
    {
      name: 'posts',
      entity: 'Post',
      label: 'Posts',
    },
  ],
  auth: {
    enabled: true,
    adapter: myAuthAdapter,
  },
  backend: {
    port: 3030,
  },
});

const core = new DynamicFormCore(config);
await core.init();
await core.start();

Type Mappings

| Prisma Type | Normalized Type | |-------------|----------------| | String | text | | Int | int | | BigInt | bigint | | Float | float | | Decimal | decimal | | Boolean | boolean | | DateTime | timestamp | | Json | json | | Bytes | bytea |

Arrays are represented with [] suffix (e.g., text[]).

Validation Rules

The inspector automatically generates validation rules based on:

  1. Field Constraints:

    • Required fields (no ?)
    • Default values
    • Unique constraints
  2. Type-based Validation:

    • Numeric types: min/max ranges
    • DateTime: valid date check
    • Boolean: boolean check
    • Json: valid JSON check
    • Arrays: array check
  3. Convention-based Validation:

    • Fields named email: email pattern
    • Fields named url: URL pattern
    • Fields named phone/tel: phone pattern

API

PrismaEntityInspector

class PrismaEntityInspector implements EntityInspector {
  // Create inspector from Prisma DMMF
  static fromDMMF(dmmf: any): PrismaEntityInspector;

  // Manually register a model
  registerModel(modelName: string, metadata: PrismaModelMetadata): void;

  // Inspect entity (required by EntityInspector interface)
  inspectEntity(entity: any): ResourceSchema;
}

License

MIT