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

Commit f701c0c

Browse files
author
Per Kristian Kummermo
committed
feat(mapperconfig): allow for backwards compitability in mapper configs
1 parent 6985bb9 commit f701c0c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/DataMapperChain.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ describe("Data mapper chain", () => {
103103
p2: "2",
104104
});
105105
});
106+
107+
it("should be able to deserialize old mapper configs", () => {
108+
const serializedConfig = `{"name":"Test","mappers":[{"ident":"MOCK","params":{"p1":1,"p2":"2"}}]}`;
109+
110+
dataMapperChain.loadConfig(serializedConfig);
111+
112+
expect(dataMapperChain.name).toBe("Test");
113+
expect(dataMapperChain.mappers.length).toBe(1);
114+
expect((dataMapperChain.mappers[0] as MapperMock).initParams).toEqual({
115+
p1: 1,
116+
p2: "2",
117+
});
118+
});
106119
});
107120

108121
describe("Mapper configuration", () => {

src/DataMapperChain.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ export class DataMapperChain {
7878
loadConfig(configString: string): DataMapperChain {
7979
const parsedConfig = JSON.parse(configString);
8080
this.name = parsedConfig.name;
81-
const mapperConfigs: IMapperConfig[] = parsedConfig.mappers;
81+
let mapperConfigs: IMapperConfig[] = [];
82+
83+
mapperConfigs = parsedConfig.mappers.map((mapper: IMapperConfig) => {
84+
if (mapper.ident) {
85+
mapper.id = mapper.ident;
86+
}
87+
88+
return mapper;
89+
});
8290

8391
mapperConfigs.forEach((config) => {
8492
const mapper = this.createMapperByConfig(config);

src/Typings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export enum IOutputType {
77

88
export interface IMapperConfig {
99
id: string;
10+
/** @deprecated */
11+
ident?: string;
1012
params: any;
1113
}
1214

0 commit comments

Comments
 (0)