@void-snippets/nestjs

@void-snippets/nestjs

defineResource() config + generated Controller/Service/Repository for a full REST resource.

#What defineResource replaces

Without this package, a single CRUD resource in NestJS usually means three hand-written classes: a repository (talks to the database), a service (business logic, calls the repository), and a controller (HTTP routes, calls the service). Multiply that by every resource in your app — contacts, invoices, tickets — and most of it is the same shape every time.

@void-snippets/nestjs generates all three from one config object:

typescript
import { defineResource } from '@void-snippets/nestjs';
import { forTypeOrmResource } from '@void-snippets/nestjs/typeorm';
import { Contact } from './contact.entity';

@Module({ imports: [forTypeOrmResource(Contact)] })
export class ContactsModule {}

Nothing else. That's a full ContactsController, ContactsService, and ContactsRepository — generated, wired together, and registered with Nest's dependency injection.

#When you outgrow the generated classes

You don't have to choose between "the package does everything" and "I write everything by hand." When a resource needs a side effect (send a welcome email after create), an extra endpoint (GET /contacts/recent), or custom validation, you extends the generated base classes instead of using the one-liner. See Adding Custom Logic.

#The four pieces

PageWhat it covers
SetupInstalling the package and configuring app-wide defaults once
defineResourceThe full reference — every option the config object accepts
MongooseRegistering a resource backed by a Mongoose schema
TypeORMRegistering a resource backed by a TypeORM entity