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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@manic.code/schema

v1.2.1

Published

A flexible schema definition and validation system for TypeScript with multi-database support

Readme

🧠 @manic.code/schema

npm version Build Status Coverage License

A powerful, flexible schema definition and validation system for TypeScript with seamless multi-database support.

🔥 Overview

MANIC Schema is a revolutionary TypeScript-first ORM/ODM that lets you define your data model once and seamlessly use it across multiple databases — MongoDB, Neo4j, PostgreSQL, and more. Built from the ground up with modern best practices:

✨ Key Features

  • Define Once, Use Anywhere: Define schema in TypeScript, deploy to any supported database
  • Multi-Database Architecture: Mix and match databases for optimal performance
  • Cross-Database Relationships: Maintain relationships between entities in different databases
  • GraphQL Ready: Auto-generate GraphQL schema from your entities
  • Database-Specific Optimizations: Leverage native database features when needed
  • Type-Safe: Full TypeScript support with proper types throughout

🏗️ Core Architecture

  • Clean Design: Explicit dependencies, no global state, no magic
  • Adapter Pattern: Extensible adapter system for database integrations
  • Decorator-Based: Intuitive TypeScript decorators for schema definition
  • 100% Test Coverage: Comprehensive test suite with property-based testing

🗄️ Supported Databases

| Database | Status | Features | | ---------- | -------------- | ----------------------------------------------- | | MongoDB | ✅ Stable | Collections, indexes, embedding | | Neo4j | ✅ Stable | Node labels, relationship types, Cypher queries | | PostgreSQL | ✅ Stable | Tables, columns, indexes, joins | | SQLite | 🚧 In Progress | Basic functionality | | Redis | 🚧 In Progress | Basic functionality | | DynamoDB | 🗓️ Planned | - | | Firestore | 🗓️ Planned | - |

🧩 Key Components

Decorators

Define your entities with TypeScript decorators:

@Entity()
class Post {
  @Id()
  id: string;

  @Property({ required: true })
  title: string;

  @Property()
  content: string;

  @Property()
  createdAt: Date;

  @ManyToOne({
    target: () => User,
    inverse: "posts",
    name: "AUTHORED",
  })
  author: User;

  @ManyToMany({
    target: () => Tag,
    inverse: "posts",
    name: "HAS_TAG",
  })
  tags: Tag[] = [];
}

Database-Specific Decorators

Optimize for specific databases when needed:

// MongoDB specific
@Collection("blog_posts")
@MongoIndex({ title: "text", content: "text" })
class Post {
  /* ... */
}

// Neo4j specific
@Labels(["Content", "BlogPost"])
@RelationshipType("TAGGED_WITH")
class Post {
  /* ... */
}

// PostgreSQL specific
@Table("blog_posts")
@Column({ name: "post_content", type: "text" })
@PgIndex({ name: "idx_post_title", columns: ["title"] })
class Post {
  /* ... */
}

SchemaBuilder & Registry

Explicit dependencies, no global state:

// Create registry and builder
const registry = new MetadataRegistry();
const builder = new SchemaBuilder(registry);

// Register your entities
builder.registerEntities([User, Post, Comment, Tag]);

Multi-Database Adapters

Use different databases for different entity types:

// Create adapters for different databases
const mongoAdapter = new MongoDBAdapter(
  registry,
  "mongodb://localhost:27017/blog"
);
const neo4jAdapter = new Neo4jAdapter(registry, "bolt://localhost:7687");
const pgAdapter = new PostgreSQLAdapter(
  registry,
  "postgres://localhost:5432/blog"
);

// Create repositories with appropriate adapters
const userRepo = new Repository<User>(User, mongoAdapter);
const postRepo = new Repository<Post>(Post, neo4jAdapter);
const tagRepo = new Repository<Tag>(Tag, pgAdapter);

Repositories

Consistent interface across all databases:

// Find by ID
const user = await userRepo.findById("user123");

// Query by criteria
const posts = await postRepo.find({ completed: true });

// Create and save
const tag = new Tag();
tag.name = "TypeScript";
await tagRepo.save(tag);

// Delete
await userRepo.delete("user123");

📊 GraphQL Integration

Automatic GraphQL schema generation:

// Generate GraphQL schema from entities
import { generateGraphQLSchema } from "@manic.codes/schema/graphql";

const typeDefs = generateGraphQLSchema(registry);
const resolvers = generateResolvers(registry, {
  User: userRepo,
  Post: postRepo,
  Tag: tagRepo,
});

// Create Apollo Server
const server = new ApolloServer({
  typeDefs,
  resolvers,
});

🚀 Complete Multi-Database Example

import {
  Entity,
  Id,
  Property,
  ManyToOne,
  ManyToMany,
  MetadataRegistry,
  SchemaBuilder,
  MongoDBAdapter,
  Neo4jAdapter,
  PostgreSQLAdapter,
  Repository,
} from "@manic.code/schema";

// Define entities
@Entity()
class User {
  @Id()
  id: string;

  @Property({ required: true })
  name: string;

  @Property({ required: true, unique: true })
  email: string;

  @OneToMany({ target: () => Post, inverse: "author" })
  posts: Post[] = [];
}

@Entity()
class Post {
  @Id()
  id: string;

  @Property({ required: true })
  title: string;

  @Property()
  content: string;

  @Property()
  createdAt: Date = new Date();

  @ManyToOne({ target: () => User, inverse: "posts" })
  author: User;

  @ManyToMany({ target: () => Tag, inverse: "posts" })
  tags: Tag[] = [];
}

@Entity()
class Tag {
  @Id()
  id: string;

  @Property({ required: true, unique: true })
  name: string;

  @ManyToMany({ target: () => Post, inverse: "tags" })
  posts: Post[] = [];
}

// Set up the registry and builder
const registry = new MetadataRegistry();
const builder = new SchemaBuilder(registry);
builder.registerEntities([User, Post, Tag]);

// Create database adapters
const mongoAdapter = new MongoDBAdapter(
  registry,
  "mongodb://localhost:27017/blog"
);
const neo4jAdapter = new Neo4jAdapter(registry, "bolt://localhost:7687");
const pgAdapter = new PostgreSQLAdapter(
  registry,
  "postgres://localhost:5432/blog"
);

// Create repositories with different adapters
const userRepo = new Repository<User>(User, mongoAdapter);
const postRepo = new Repository<Post>(Post, neo4jAdapter);
const tagRepo = new Repository<Tag>(Tag, pgAdapter);

// Create entities with relationships across databases
async function createBlogPost() {
  // Create user in MongoDB
  const user = new User();
  user.id = "user1";
  user.name = "John Doe";
  user.email = "[email protected]";
  await userRepo.save(user);

  // Create tags in PostgreSQL
  const tag1 = new Tag();
  tag1.id = "tag1";
  tag1.name = "TypeScript";
  await tagRepo.save(tag1);

  const tag2 = new Tag();
  tag2.id = "tag2";
  tag2.name = "ORM";
  await tagRepo.save(tag2);

  // Create post in Neo4j with relationships to MongoDB and PostgreSQL
  const post = new Post();
  post.id = "post1";
  post.title = "Multi-Database ORM with TypeScript";
  post.content = "This is amazing...";
  post.author = user;
  post.tags.push(tag1, tag2);
  await postRepo.save(post);

  return post;
}

🔧 Installation

npm install @manic.code/schema

📄 License

MIT © Zach Winter