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

@nestjs-automapper/nestjs

v2.0.1

Published

NestJS integration for @nestjs-automapper

Readme

@nestjs-automapper/nestjs

NestJS integration: module, DI, response mapping, request-body mapping, and a CI check.

pnpm add @nestjs-automapper/nestjs @nestjs-automapper/typeorm

Peers: @nestjs/common, @nestjs/core, reflect-metadata, rxjs.

Setup

@Module({
  imports: [
    AutomapperModule.forRoot({
      adapters: [typeorm(dataSource)],
      dtos: [ReadUserDto, CreateUserDto],
    }),
  ],
})
export class AppModule {}

The mapper seals at boot. A DTO with an unresolved field fails nest start with the field, the source, the adapter, and a did-you-mean — not the request that happens to hit it.

Nested relations are closed over automatically, so only top-level DTOs go in dtos.

Async configuration

With @nestjs/typeorm, inject the DataSource so the adapter reads metadata from the live connection:

AutomapperModule.forRootAsync({
  inject: [DataSource],
  useFactory: (dataSource: DataSource) => ({
    adapters: [typeorm(dataSource)],
    dtos: [ReadUserDto, CreateUserDto],
  }),
});

useClass and useExisting also work, via AutomapperOptionsFactory.

Reading

@Controller('users')
export class UsersController {
  constructor(@InjectMapper() private readonly mapper: Mapper) {}

  @Get()
  @MapTo(ReadUserDto)
  findAll() {
    return this.repo.find(this.mapper.nativeProjectionFor(ReadUserDto) as FindManyOptions<User>);
  }
}

@MapTo maps the handler's return value — single object or array. Routes without it pass through untouched.

Writing

export class CreateUserDto extends Write(User, ['email', 'password']) {}

@Post()
create(@Body() dto: CreateUserDto) {
  return this.service.create(dto);
}

Plain @Body(). MapBodyPipe is registered globally and reads the parameter's type, so there is no factory call at the parameter and no service locator.

A client sending id or createdAt gets a 400 naming what was rejected and what is accepted. @automapper/nestjs's MapPipe maps whatever it is handed; this knows which fields the client may not supply, because it read the schema.

Bodies whose type is not a Write DTO are left alone.

CI

npx automapper check dist/app.module.js

Boots the application context, so CI validates the same pair set the running app seals. Exit code 1 with the diagnostics if anything is unresolved.

Multiple mappers

AutomapperModule.forRoot({ name: 'tenant-a', adapters: [...] });

constructor(@InjectMapper('tenant-a') private readonly mapper: Mapper) {}

Swagger

Computed fields have no declaration site for @ApiProperty, so generate the schema instead. The mapper is sealed during boot, after decorators have run, so register the schema on the document in main.ts and reference it:

const mapper = app.get<Mapper>(getMapperToken());
const document = SwaggerModule.createDocument(app, config);
document.components = {
  ...document.components,
  schemas: { ...document.components?.schemas, ReadUserDto: mapper.schemaOf(ReadUserDto) as object },
};
SwaggerModule.setup('docs', app, document);
@ApiOkResponse({ schema: { $ref: '#/components/schemas/ReadUserDto' } })

Options

| | | |---|---| | adapters | schema adapters, in arbitration order | | dtos | top-level DTOs to plan | | interceptor | register MapToInterceptor globally. Default true | | bodyPipe | register MapBodyPipe globally. Default true | | name | register under a named token |

License

MIT