Skip to content

Commit

Permalink
feat(pojos): expose instantiate as public API
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Mar 6, 2021
1 parent 53343f9 commit 528b193
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/pojos/src/lib/pojos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createInitialMapping } from '@automapper/core';
import type { CreateMapOptions, MapPluginInitializer } from '@automapper/types';
import type {
CreateMapOptions,
Dictionary,
MapPluginInitializer,
} from '@automapper/types';
import { MappingClassId } from '@automapper/types';
import {
PojosMappingStorage,
Expand All @@ -13,6 +17,12 @@ export const pojos: MapPluginInitializer<string> = (errorHandler) => {
const mappingStorage = new PojosMappingStorage();

return {
instantiate<TModel extends Dictionary<TModel> = any>(
model: string,
obj?: TModel
) {
return instantiate(metadataStorage, model, obj);
},
initializeMapping(
source: string,
destination: string,
Expand All @@ -27,15 +37,11 @@ export const pojos: MapPluginInitializer<string> = (errorHandler) => {

exploreMetadata(metadataStorage, source, destination);

const [destinationObj, destinationNestedMetadataMap] = instantiate(
metadataStorage,
const [destinationObj, destinationNestedMetadataMap] = this.instantiate(
destination
);

const [sourceObj, sourceNestedMetadataMap] = instantiate(
metadataStorage,
source
);
const [sourceObj, sourceNestedMetadataMap] = this.instantiate(source);

return createInitialMapping(
sourceObj,
Expand All @@ -62,8 +68,8 @@ export const pojos: MapPluginInitializer<string> = (errorHandler) => {
return;
}

const [sourceObj] = instantiate(metadataStorage, source);
const [destinationObj] = instantiate(metadataStorage, destination);
const [sourceObj] = this.instantiate(source);
const [destinationObj] = this.instantiate(destination);

mapping[MappingClassId.mappings] = [sourceObj, destinationObj];
return mapping;
Expand Down

0 comments on commit 528b193

Please sign in to comment.