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

@inixiative/prisma-map

v0.1.0

Published

Extracts a complete model map (fields, relations, FK info) from a Prisma generated client — supports v6 (schema.prisma) and v7 (runtimeDataModel)

Readme

@inixiative/prisma-map

Extract a structured, runtime-friendly model map from a Prisma generated client.

@inixiative/prisma-map builds a PrismaMap object that includes:

  • Models and fields
  • Field kinds (scalar, enum, object)
  • Relation FK direction (fromFields, toFields)
  • Model DB table name (@@map) as dbName
  • Enum values (ordered)

It supports both Prisma client layouts:

  • Prisma v7: parse generated internal/class.ts
  • Prisma v6: parse generated schema.prisma

Installation

bun add @inixiative/prisma-map

or

npm i @inixiative/prisma-map

Quick Start

Prisma v7

import { buildPrismaMapV7 } from '@inixiative/prisma-map';

const map = buildPrismaMapV7();
// or: buildPrismaMapV7('/absolute/path/to/generated/client')

console.log(map.User.fields.posts);

Prisma v6

import { buildPrismaMapV6 } from '@inixiative/prisma-map';

const map = buildPrismaMapV6();
// or: buildPrismaMapV6('/absolute/path/to/generated/client')

console.log(map.Post.fields.author);

Output Shape

The library returns:

type PrismaMap = Record<string, {
  dbName: string | null;
  fields: Record<string, ScalarField | EnumField | RelationField>;
}>;

Scalar field

{
  "kind": "scalar",
  "type": "String",
  "isRequired": true,
  "isList": false,
  "isId": false
}

Enum field

{
  "kind": "enum",
  "type": "UserRole",
  "isRequired": true,
  "isList": false,
  "values": ["ADMIN", "USER", "GUEST"]
}

Relation field

{
  "kind": "object",
  "type": "User",
  "isList": false,
  "isRequired": true,
  "relationName": "AuthoredPosts",
  "fromFields": ["authorId"],
  "toFields": ["id"]
}

fromFields/toFields are empty arrays on back-relations.

Example End-to-End

Given:

enum Role {
  ADMIN
  USER
}

model User {
  id    String @id
  role  Role
  posts Post[]

  @@map("users")
}

model Post {
  id       String @id
  authorId String
  author   User   @relation("AuthoredPosts", fields: [authorId], references: [id])
}

A representative map:

{
  "User": {
    "dbName": "users",
    "fields": {
      "id": {
        "kind": "scalar",
        "type": "String",
        "isRequired": true,
        "isList": false,
        "isId": true
      },
      "role": {
        "kind": "enum",
        "type": "Role",
        "isRequired": true,
        "isList": false,
        "values": ["ADMIN", "USER"]
      },
      "posts": {
        "kind": "object",
        "type": "Post",
        "isList": true,
        "isRequired": true,
        "fromFields": [],
        "toFields": []
      }
    }
  },
  "Post": {
    "dbName": null,
    "fields": {
      "author": {
        "kind": "object",
        "type": "User",
        "isList": false,
        "isRequired": true,
        "relationName": "AuthoredPosts",
        "fromFields": ["authorId"],
        "toFields": ["id"]
      }
    }
  }
}

API

Root exports:

import {
  buildPrismaMapV6,
  buildPrismaMapV7,
  getRelations,
  relationForeignKey,
  parseTagClasses,
  type PrismaMap,
  type ModelEntry,
  type ModelField,
  type ScalarField,
  type EnumField,
  type RelationField,
  type IndexEntry,
  type RelationInfo,
  type Identifier,
  type Annotations,
} from '@inixiative/prisma-map';

Version-specific exports:

import { buildPrismaMapV7, parseRuntimeDataModel, parseInlineSchema, parseRelationFks, parseEnumValues, parseSchemaStructure } from '@inixiative/prisma-map/v7';
import { buildPrismaMapV6, parseSchemaText, buildFromSchemaFile } from '@inixiative/prisma-map/v6';

Relation Traversal

getRelations(map, modelName) lists a model's relation fields with their foreign keys collapsed for lookup; relationForeignKey(field) does the collapse alone.

import { getRelations } from '@inixiative/prisma-map';

getRelations(map, 'Inquiry');
// [
//   { relationName: 'organization', targetModel: 'Organization', isList: false,
//     foreignKey: { id: 'organizationId' } },
//   { relationName: 'parent', targetModel: 'Inquiry', isList: false,
//     foreignKey: { id: 'parentId' }, annotations: { tree: { parent: true } } },
//   { relationName: 'children', targetModel: 'Inquiry', isList: true, foreignKey: null },
// ]

foreignKey is a bare field name for a single same-named pair, a { referencedField: localField } map otherwise, and null for back-relations. Functions are string-keyed and ORM-agnostic — wrap them with your generated ModelName types if you want typed accessors.

Annotation DSL (/// @tagClass(key: value))

Prisma rejects custom attributes, but preserves /// doc comments into the generated client's inlineSchema. prisma-map parses a small, forward-looking DSL out of those comments and records it — domain-agnostically — under annotations.

model Category {
  id       String     @id
  parentId String?
  /// @tree(parent: true)
  parent   Category?  @relation("tree", fields: [parentId], references: [id])
  children Category[] @relation("tree")

  /// @search(fuzzy: true)
  @@index([name])
}
map.Category.fields.parent.annotations; // { tree: { parent: true } }
map.Category.indexes;
// [{ kind: 'index', fields: ['name'], annotations: { search: { fuzzy: true } } }]
  • Grammar: @<tagClass>(<key>: <value>, …); multiple tag classes per line allowed.
  • Values: true/false → boolean, numerics → number, "quoted"/bare words → string, [a, b] → array.
  • Placement: a /// run binds to the declaration directly below it — a model, a field, or an index (@@index / @@unique / @@id / @@fulltext). A blank line or a plain // breaks the binding.
  • prisma-map only records the bag; what a tag class means (e.g. tree.parent → "don't auto-recurse up this self-relation") is the consumer's to decide.

Auto-Detection Behavior

If you omit the path, the library walks upward from process.cwd() and checks common generated client locations:

  • node_modules/.prisma/client
  • node_modules/@prisma/client
  • prisma/generated/client
  • src/generated/client
  • src/generated/prisma
  • generated/client

v7 detection requires internal/class.ts. v6 detection requires schema.prisma and excludes directories that also have internal/class.ts.

Practical Use Cases

  • Build rule-engine metadata for JSON rules
  • Resolve template/package dependency graphs via relation edges
  • Generate guardrails (for example, "entity X must include relation Y")
  • Build field-level introspection UIs

Notes and Limits

  • The output uses logical Prisma field names.
  • Field-level DB aliases (@map on fields) are not emitted today.
  • Model DB alias (@@map) is emitted as dbName.
  • Native DB type annotations (for example @db.Text) are not emitted.
  • relationName is included when available in Prisma runtime metadata.

Development

bun run test
bun run typecheck
bun run check
bun run build

License

MIT