mapper
mapper copied to clipboard
Consistent way to ignore properties
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the issue
I am using transformer-plugin as instructed from the documentation with,
- NestJS
- TypeORM
- Mongo
I found out that the automapper still requires to explicitly define mapping between classes which is kind of expected thing probably. I am using the mappings with mapping profiles with ignore mapping configuration to ignore some properties.
These ignore configurations do not work as I have to use JSDoc comment to ignore the properties. Is there a chance to have a consistent way to ignore the properties (preferably with profiles as those are already needed)?
Maybe another bug - the reason to use ignore configuration in first place
The transformer plugin fails for type ObjectID (for TypeORM - Mongo) which somehow uses date type internally with error,
return Object.getPrototypeOf(value) === date || value === Date;
....@automapper/core/index.cjs:118
TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf(<anonymous>)
....
Models/DTOs/VMs
@Entity()
export default class Person {
@ObjectIdColumn()
id: ObjectId;
..
}
Mapping configuration
No response
Steps to reproduce
In case of ObjectID,
-
npm i
-
npm start:dev
- See error
Expected behavior
- [ ] The automapper should be able to map the ObjectID field without any errors
- [ ] A way to ignore the properties consistently with transformer-plugin.
Screenshots
No response
Minimum reproduction code
No response
Package
- [ ] I don't know.
- [ ]
@automapper/core
- [X]
@automapper/classes
- [X]
@automapper/nestjs
- [ ]
@automapper/pojos
- [ ]
@automapper/mikro
- [ ]
@automapper/sequelize
- [ ] Other (see below)
Other package and its version
No response
AutoMapper version
8.7.7
Additional context
Linux Node 16
I agree, there are some issue this the generated JS when using some imported types and generics. Here is a quick example typegoose:
Source typescript:
import { prop, Ref } from "@typegoose/typegoose";
import { AutoMap } from "@automapper/classes";
import mongoose from "mongoose";
export class Car {}
export class Person {
@prop({ ref: () => Car })
@AutoMap(() => Car)
public car: Ref<Car, mongoose.Types.ObjectId>;
}
Resulting Javascript :
const typegoose_1 = require("@typegoose/typegoose");
const classes_1 = require("@automapper/classes");
class Car {
}
exports.Car = Car;
class Person {
static __AUTOMAPPER_METADATA_FACTORY__() {
return [
//Produce the error "Identifier expected.ts(1003)"
["car", { type: () => require("./node_modules/.pnpm/@[email protected][email protected]/node_modules/@typegoose/typegoose/lib/types").Ref<import("/sources/emoko-back-next/testing/typegoose/models.entity").Car, import("mongoose").Types.ObjectId>, depth: 1 }]
];
}
}
__decorate([
(0, typegoose_1.prop)({ ref: () => Car }),
(0, classes_1.AutoMap)(() => Car),
__metadata("design:type", Object)
], Person.prototype, "car", void 0);
For now, I use this solution to avoid those errors:
/**
* @autoMapIgnore
*/
@AutoMap(() => Car)
public car: Ref<Car, mongoose.Types.ObjectId>;
@nartc I guess a quick solution would be to have the transfomer plugin ignoring entirely the property when there is an AutoMap
decorator.