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

typeorm-entity-schema-renderer

v0.1.0

Published

Render a TypeORM EntitySchema back to a fully-decorated TypeScript entity class source

Readme

typeorm-entity-schema-renderer

Render a TypeORM EntitySchema back into a fully-decorated TypeScript entity class source.

Takes a new EntitySchema({...}) (or a plain options object) and produces a printable .ts source with:

  • @Entity / @ViewEntity / @ChildEntity class decorators
  • @Tree, @TableInheritance
  • Class-level @Index / @Unique / @Check / @Exclusion
  • @Column, @PrimaryColumn, @PrimaryGeneratedColumn, @CreateDateColumn, @UpdateDateColumn, @DeleteDateColumn, @VersionColumn, @Generated
  • @ViewColumn
  • @OneToOne / @OneToMany / @ManyToOne / @ManyToMany / @TreeParent / @TreeChildren with @JoinColumn / @JoinColumns / @JoinTable
  • @RelationId
  • Correct TS types for fields: Relation<T> (non-lazy), Promise<T> (lazy), T[] (*-to-many), T | null (nullable), enum union, redundant column-type omission
  • External import { ... } from '...' lines driven by a pluggable importResolver

Install

npm install typeorm-entity-schema-renderer

typeorm is an optional peer dependency — it is only needed if you construct input via new EntitySchema(...); the library itself has no runtime dependency on TypeORM.

Usage

import { EntitySchema } from "typeorm"
import { EntitySchemaRenderer } from "typeorm-entity-schema-renderer"

const UserSchema = new EntitySchema({
    name: "User",
    tableName: "users",
    columns: {
        id: { type: Number, primary: true, generated: "increment" },
        email: { type: "varchar", length: 255, unique: true },
        createdAt: { type: "timestamp", createDate: true },
    },
})

const renderer = new EntitySchemaRenderer()
console.log(renderer.render(UserSchema))

Output:

import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'

@Entity({ name: "users" })
export class User {
  @PrimaryGeneratedColumn("increment")
  readonly id!: number;

  @Column({ length: 255, unique: true })
  email!: string;

  @CreateDateColumn({ type: "timestamp" })
  readonly createdAt!: Date;
}

Custom importResolver

Control where external references (relations, embeddeds, enum classes) are imported from:

import { EntitySchemaRenderer, ImportResolver } from "typeorm-entity-schema-renderer"

const resolver: ImportResolver = (name, { kind }) => {
    switch (kind) {
        case "embedded":
            return { path: `@/embeddeds/${name}`, name }
        case "enum":
            return { path: `@/enums/${name}`, name }
        case "entity":
        case "relation":
        default:
            return { path: `@/entities/${name}`, name }
    }
}

const renderer = new EntitySchemaRenderer({ importResolver: resolver })

ImportKind values:

| Kind | Source | |------|--------| | entity | parent class referenced via base | | relation | targets of @OneToOne / @OneToMany / @ManyToOne / @ManyToMany / @TreeParent / @TreeChildren | | embedded | targets of @Column(() => X) embeddeds | | enum | enum classes referenced by enum columns |

The resolver may return:

  • { path, name } — explicit import path and symbol name
  • a string — treated as the path; the original name is kept
  • undefined — skip the import

API

new EntitySchemaRenderer(options?)

| Option | Type | Description | |--------|------|-------------| | importResolver | ImportResolver | Resolves external reference names to import paths. Defaults to ./<Name> (same directory) for every kind. |

.render(schema) => string

Accepts an EntitySchema instance or a plain options object. Throws TypeError on invalid input.

.buildExternalImports(schema, options?) => string

Returns just the import { ... } from '...' block for external references. Useful if you assemble the output yourself.

License

MIT