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

@svintsoff78/megamock

v1.0.6

Published

Simple NestJS mock generation with decorators

Readme

🚀 MegaMock for NestJS

MegaMock is a declarative mock generator for NestJS.
It creates mock API responses directly from class definitions using decorators — no json-server, no swagger mocker, no manual fixtures.



✨ Features

  • 🎯 Generate mock API responses via the @MockRoute decorator
  • 🧩 Nested entities with @MockProperty({ type: User })
  • 🔄 Array generation with random lengths
  • ❓ Nullable fields with automatic probability
  • 🧱 Depth limit to prevent circular structures
  • 📦 Works with HTTP, WebSockets, tests, and local development
  • 🔌 No external mock servers or JSON files required

📦 Installation

npm install @megamock/nest
# or
yarn add @megamock/nest

🚀 Quick Start

1. Create a mock DTO (not tied to ORM entities)

import { MockProperty } from '@svintsoff78/megamock';

export class UserMock {
  @MockProperty({ type: 'id' })
  id: number;

  @MockProperty({ type: 'string' })
  name: string;

  @MockProperty({ type: 'string', nullable: true })
  avatarUrl: string | null;
}

2. Nested mock entities and arrays

import { MockProperty } from '@svintsoff78/megamock';
import { UserMock } from './user.mock';

export class ChatMock {
  @MockProperty({ type: 'id' })
  id: number;

  @MockProperty({ type: 'title' })
  title: string;

  @MockProperty({
    type: UserMock,
    isArray: true,
    arrayLength: [2, 6],
  })
  participants: UserMock[];
}

3. Generate mock responses via @MockRoute

import { Controller, Get } from '@nestjs/common';
import { MockRoute } from '@megamock/nest';
import { ChatMock } from './chat.mock';

@Controller('chats')
export class ChatController {
  @Get()
  @MockRoute(ChatMock, { isArray: true, arrayLength: [3, 5] })
  findAll() {}

  @Get(':id')
  @MockRoute(ChatMock)
  findOne() {}
}

MegaMock will fully generate the response for these routes.


⚙️ MockRoute Options

@MockRoute(ChatMock, {
  isArray: true,
  arrayLength: [min, max]
})

| Option | Description | Required? | |--------------|-----------------------------------------------------|-----------| | isArray | Generate a list of entities instead of a single one | false | | arrayLength | Random array length within the provided range | false |

⚙️ MockProperty Options

@MockProperty({ 
    type: 'string',
    nullable: true,
    isArray: true,
    arrayLength: [min, max]
})

| Option | Description | Required? | |---------------|------------------------------------------------------------|-----------| | type | string, number, boolean, uuid, date, Type<any> | true | | nullable | Can the property be nullable | false | | isArray | Generate a list of entities instead of a single one | false | | arrayLength | Random array length within the provided range | false |


🧠 Why MegaMock?

  • ✔ Response types always match your DTOs
  • ✔ No duplicated mock JSON files
  • ✔ No external mock servers
  • ✔ Great for frontend-backend parallel development
  • ✔ Works natively with NestJS decorators and interceptors
  • ✔ Consistent and predictable data generation

🗺 Roadmap

  • 🔮 Faker integration (names, emails, lorem, addresses)
  • ♻ Record mode (save real responses and replay them as mocks)
  • 📚 Swagger examples autogeneration
  • 🎛 Custom generators for advanced scenarios
  • 🧬 Fine-grained rules for nested structures
  • 🎨 Playground UI for inspecting mock outputs

🤝 Contributing

Contributions are welcome! Open an issue or PR — let's build MegaMock together.


📄 License

MIT — free to use, modify, and distribute.


⭐ If MegaMock helps you — consider starring the repository!