TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published


status coverage Latest Release

See on NPM

Map Ts.ED request parameters to any object!


You can get the latest release and the type definitions using npm:

$ npm install @jojoxd/tsed-entity-mapper reflect-metadata
// Server.ts
import "reflect-metadata";
import "@jojoxd/tsed-entity-mapper";

// <snip>

    // No configuration required
export class Server {}

⚠️ Important: Don't skip the reflect-metadata package. It is required to extract the types from your controller methods.
You also need "emitDecoratorMetadata": true in your tsconfig.


Creating a Mapper

The Entity Mapper is the core of translating parameters to an object.

import { Inject } from "@tsed/di";
import { EntityMapper } from "@jojoxd/tsed-entity-mapper";
import { MyEntity } from "../entity/my-entity";
import { MyEntityRepository } from "../entity/repository/my-entity-repository";

export class MyEntityMapper implements EntityMapperMethods<MyEntity>
    // EntityMapper is an injectable, so Inject works here

    protected entityRepository: MyEntityRepository;

    async map(value: unknown, ctx: EntityMapperMapContext<MyEntity>): Promise<MyEntity>
        return this.entityRepository.find({ id: value });

Using an Entity Mapper in a controller

Entity mappers are used when you specify a parameter decorator:

// Using the above defined Entity Mapper

import { Get, Post } from "@tsed/schema";
import { Controller } from "@tsed/common";
import { BodyParamEntity, QueryParamEntity, PathParamEntity } from "@jojoxd/tsed-entity-mapper";
import { MyEntity } from "../entity/my-entity";

export class MyController
    getMyEntity(@QueryParamEntity('id') entity: MyEntity)
        // entity will be resolved as a MyEntity

    async postMyEntity(@BodyParamEntity() entity: MyEntity)
        // entity will be resolved as a MyEntity
    async getById(@PathParamEntity('id') entity: MyEntity)
        // entity will be resolved as a MyEntity

Using the Entity Mapper itself:

It currently is not possible to use the Entity Mapper by itself.


  • [ ] Better Exception Handling
  • [ ] Extract mapping functionality from EntityMapperPipe into a usable service


npm i @jojoxd/tsed-entity-mapper

DownloadsWeekly Downloads






Unpacked Size

34.5 kB

Total Files


Last publish


  • bakaxd