Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
feat(mapperconfig): allow for backwards compitability in mapper configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Kristian Kummermo committed Dec 3, 2018
1 parent 6985bb9 commit f701c0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/DataMapperChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ describe("Data mapper chain", () => {
p2: "2",
});
});

it("should be able to deserialize old mapper configs", () => {
const serializedConfig = `{"name":"Test","mappers":[{"ident":"MOCK","params":{"p1":1,"p2":"2"}}]}`;

dataMapperChain.loadConfig(serializedConfig);

expect(dataMapperChain.name).toBe("Test");
expect(dataMapperChain.mappers.length).toBe(1);
expect((dataMapperChain.mappers[0] as MapperMock).initParams).toEqual({
p1: 1,
p2: "2",
});
});
});

describe("Mapper configuration", () => {
Expand Down
10 changes: 9 additions & 1 deletion src/DataMapperChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ export class DataMapperChain {
loadConfig(configString: string): DataMapperChain {
const parsedConfig = JSON.parse(configString);
this.name = parsedConfig.name;
const mapperConfigs: IMapperConfig[] = parsedConfig.mappers;
let mapperConfigs: IMapperConfig[] = [];

mapperConfigs = parsedConfig.mappers.map((mapper: IMapperConfig) => {
if (mapper.ident) {
mapper.id = mapper.ident;
}

return mapper;
});

mapperConfigs.forEach((config) => {
const mapper = this.createMapperByConfig(config);
Expand Down
2 changes: 2 additions & 0 deletions src/Typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export enum IOutputType {

export interface IMapperConfig {
id: string;
/** @deprecated */
ident?: string;
params: any;
}

Expand Down

0 comments on commit f701c0c

Please sign in to comment.