custom-automapper
Version:
A powerful, type-safe object mapping library for TypeScript and NestJS
59 lines • 2.5 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var AutomapperModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutomapperModule = void 0;
const common_1 = require("@nestjs/common");
const mapper_1 = require("../core/mapper");
let AutomapperModule = AutomapperModule_1 = class AutomapperModule {
static forRoot(options) {
const mapperProvider = {
provide: mapper_1.Mapper,
useFactory: () => {
const mapper = new mapper_1.Mapper({
...(options?.globalOptions || {}),
cache: options?.cache
});
if (options?.profiles) {
options.profiles.forEach(ProfileClass => {
new ProfileClass(mapper);
});
}
return mapper;
}
};
const profileProviders = options?.profiles?.map(ProfileClass => ({
provide: ProfileClass,
useFactory: (mapper) => new ProfileClass(mapper),
inject: [mapper_1.Mapper]
})) || [];
return {
module: AutomapperModule_1,
providers: [mapperProvider, ...profileProviders],
exports: [mapper_1.Mapper, ...profileProviders]
};
}
static forFeature(profiles) {
const profileProviders = profiles.map(ProfileClass => ({
provide: ProfileClass,
useFactory: (mapper) => new ProfileClass(mapper),
inject: [mapper_1.Mapper]
}));
return {
module: AutomapperModule_1,
providers: profileProviders,
exports: profileProviders
};
}
};
exports.AutomapperModule = AutomapperModule;
exports.AutomapperModule = AutomapperModule = AutomapperModule_1 = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({})
], AutomapperModule);
//# sourceMappingURL=automapper.module.js.map