For the complete documentation index, see llms.txt. This page is also available as Markdown.

Mapper

A mapper converts between a domain Entity and its persistence Model, keeping storage details out of the domain. Implement the Mapper<EntityType, ModelType> interface in the feature's data/ folder.

import { Mapper } from '@soapjs/soap';
import { Character } from '../domain/character.entity';
import { CharacterDocument } from './character.dto';

export class CharacterMapper implements Mapper<Character, CharacterDocument> {
  toEntity(doc: CharacterDocument): Character {
    return new Character(doc._id, doc.name, doc.universe, doc.alignment, doc.createdAt, doc.updatedAt);
  }

  toModel(entity: Character): CharacterDocument {
    return {
      _id: entity.id,
      name: entity.name,
      universe: entity.universe,
      alignment: entity.alignment,
      createdAt: entity.createdAt,
      updatedAt: entity.updatedAt,
    };
  }
}
  • toEntity(model) — DB document → domain entity (e.g. _idid)

  • toModel(entity) — domain entity → DB document

The mapper is handed to a DatabaseContext alongside a Source:

Last updated