entities-ui
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

Entity UI

Table of Contents

Overview

Entity Docs Generator is a TypeScript-based library that automates the creation of entity UI. It provides decorators for defining table and column properties, and dynamically generates an HTML representation of the schema. see example output below

Logo

Installation

To use this library in your project, install it via npm:

npm install entities-ui

Decorators

@Table

The Table decorator defines metadata for database tables.

Properties

Property Type Required Default Description
name string No - The name of the table in the database
description string No - Human-readable column description for table

Example:

import { Table, Props } from "entity-generator";

@Table({
  name: "users",
  description: "Users table",
})
class TestUser {
  first_name: string;
  last_name: string;
}

@Props

The Props decorator defines column properties for a table.

Properties

Property Type Required Default Description
name string No - The name of the column in the database table
type SqlDataType Yes - The SQL data type for the column (e.g., VARCHAR, INTEGER, BOOLEAN)
nullable boolean No false Whether the column allows NULL values.
default any No - Default value for the column.
primary_key boolean No false Whether the column is a PRIMARY KEY
indexed boolean No false Whether to create an index for this column
example any No - Example value for documentation purposes
description string No - Human-readable column description for documentation

Example Usage

Example:

class Product {
  @Props({
    type: "String",
    name: "first_name",
    nullable: false,
    example: "John",
    description: "First name of the user",
  })
  first_name: string;
  @Props({
    type: "String",
    name: "last_name",
    nullable: false,
    example: "Doe",
    description: "Last name of the user",
  })
  last_name: string;
}

TypeOrm

@Table({
  name: "users",
  description: "Users table",
})
@Entity()
class User {
  @Column({
    type: "varchar",
  })
  @Props({
    type: "String",
    name: "first_name",
    nullable: false,
    example: "John",
    description: "First name of the user",
  })
  first_name: string;

  @Column({
    type: "varchar",
  })
  @Props({
    type: "String",
    name: "last_name",
    nullable: false,
    example: "Doe",
    description: "Last name of the user",
  })
  last_name: string;
}

Mongoose

@Table({
  name: "users",
  description: "Users table",
})
@Schema({ timestamps: true })
export class Product extends Document {
  @Prop({
    type: String,
  })
  @Props({
    type: "String",
    name: "first_name",
    nullable: false,
    example: "John",
    description: "First name of the user",
  })
  first_name: string;

  @Prop({
    type: String,
  })
  @Props({
    type: "String",
    name: "last_name",
    nullable: false,
    example: "Doe",
    description: "Last name of the user",
  })
  last_name: string;
}

Initializing Schema Generator

To generate documentation, initialize the EntityGenerator with the defined entities and the Express app instance.

Express App

import { express } from "express";

const schema = EntityGenerator.initialize([User, Product], app)
  .addEntities()
  .setTitle("Entity UI")
  .setDescription(
    "This document provides an overview of all database tables and their columns."
  )
  .setVersion("0.0.1")
  .build();
const app = express();
app.get("/api-docs", (req, res) => {
  res.send(schema);
});

Nestjs App

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const schemas = EntityGenerator.initialize([Users])
    .setTitle("Entity UI")
    .setDescription(
      "This document provides an overview of all database tables and their columns."
    )
    .setVersion("0.0.1")
    .build();

  const expressApp = app.getHttpAdapter().getInstance();
  expressApp.get("/api-docs", (req, res) => res.send(schemas));

  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();

Use Cases

  • Database Documentation: Automatically generate schema documentation UI for your database tables.
  • API Development: Define structured metadata for your database and expose it via an endpoint.
  • Data Validation: Ensure consistency in table and column definitions across projects.

License

This library is licensed under the MIT License.

Package Sidebar

Install

npm i entities-ui

Weekly Downloads

6

Version

0.0.6

License

MIT

Unpacked Size

60.6 kB

Total Files

37

Last publish

Collaborators

  • alvxodus