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/core

v2.0.1

Published

Schema-aware object mapping for TypeScript — zero dependencies

Readme

@nestjs-automapper/core

The mapping engine. Zero runtime dependencies.

You normally install an adapter and the NestJS integration rather than this package directly — but everything here works standalone.

pnpm add @nestjs-automapper/core

Why

Most mappers make you restate what your types already say, then fail quietly when you forget. This one reads your schema, so it can check the mapping at boot, tell you which columns a DTO actually needs, and refuse fields the database owns.

Defining a DTO

Pick and extend return real runtime classes — no decorators, no build plugin.

import { Pick, extend, compute } from '@nestjs-automapper/core';

export class ReadUserDto extends extend(Pick(User, ['id', 'email', 'createdAt']), {
  fullName: compute<User, string>(['firstName', 'lastName'], (u) => `${u.firstName} ${u.lastName}`),
}) {}

fullName is declared once. Its return type becomes the field's static type, and its function becomes the runtime resolution.

Resolvers take the source and output types explicitly (compute<User, string>). Inside extend there is nothing to infer the source from, and the explicit source type is what makes dependency paths type-checked.

Use a class declaration, not const X = extend(...) plus type X = InstanceType<typeof X>. The self-referential alias makes TypeScript fall back to the key parameter's constraint, and the DTO silently regains every field of the source.

Mapping

import { Mapper } from '@nestjs-automapper/core';

const mapper = new Mapper().use(adapter).register(ReadUserDto);
mapper.seal();                       // builds every plan; throws nothing, reports

mapper.map(row, ReadUserDto);
mapper.mapArray(rows, ReadUserDto);
await mapper.mapAsync(row, AvatarDto);

map() before seal() throws, and register() after it throws. Lazy first-call planning is unreachable, so a broken mapping cannot reach a request.

Resolvers

| | | |---|---| | auto(name) | copy by name | | from(path) | rename, or read a nested path | | compute(deps, fn) | derived value; deps are declared | | resolve(deps, asyncFn) | async derived value | | constant(value) | fixed value | | ignore() | deliberately unmapped | | defaultTo(inner, fallback) | substitute for null/undefined, and narrow the type | | visible(pred, inner) | show only when the context predicate passes | | nested(() => Dto) | to-one relation | | collection(() => Dto) | to-many relation |

Dependencies are declared rather than inferred. A lambda is opaque: nothing about fullName reveals that it needs firstName and lastName, so a projector that guessed would under-fetch and the field would resolve to "undefined undefined".

Paths are typed, so a typo is a compile error — and TypeScript suggests the fix:

compute<User, string>(['firstNmae'], …)   // Type '"firstNmae"' is not assignable to Path<User>.
                                          // Did you mean '"firstName"'?

Projection

Ask a DTO which columns it needs:

mapper.projectionFor(ReadUserDto);
// { fields: ['id','email','createdAt','firstName','lastName'], relations: {} }

mapper.nativeProjectionFor(ReadUserDto);   // your ORM's find options

fields: [] means exactly none, never everything. A plan with context-gated fields throws without a context rather than projecting the union — the union silently over-fetches, which is the failure this exists to prevent.

Write path

import { Write } from '@nestjs-automapper/core';

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

mapper.mapInput(body, CreateUserDto);

A write DTO declaring a database-owned field fails at seal(). A body carrying one is rejected at runtime, listing what was refused and what is accepted — mass-assignment protection derived from the schema.

select: false columns are deliberately not database-owned: password is hidden on read and required on write.

OpenAPI

mapper.schemaOf(ReadUserDto);                    // 3.0, `nullable: true`
mapper.schemaOf(ReadUserDto, { version: '3.1' }); // type union

Computed fields have no declaration site for @ApiProperty, so the schema is generated instead. A nullable column is required and nullable; a gated field is optional, because undefined never crosses the wire.

Object graphs

seal() closes over the DTOs your relations reference, so nested pairs never need registering by hand. Cycles terminate and shared references map once:

a.manager.manager === a     // the cycle closes
posts[0] === posts[1]       // one shared source, one mapped instance

Per-operation state is created per map() call and discarded on return.

Type converters

new Mapper({ convert: { date: v => (v as Date).toISOString() } });

Every date field converted from one rule, none of them named. Only possible because each node carries its declared type.

Writing an adapter

interface SchemaAdapter {
  readonly name: string;
  supports(type: ClassLike): boolean;              // pure, must not throw
  describe(type: ClassLike): TypeDescriptor;       // everything, no policy
  toNativeProjection?(sel: FieldSelection, type: ClassLike): unknown;
}

describe() reports every field the schema declares and applies no filtering. Policy belongs to the planner alone — an adapter that dropped select: false columns would make password unmappable, and one with a private drop list would leak a generated column.

Every provenance flag is required. false must mean "checked and no", never "not looked at".

License

MIT