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

Commit 6985bb9

Browse files
author
Per Kristian Kummermo
committed
feat(versioned-configs): add version to serialized config
1 parent 609eab5 commit 6985bb9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/DataMapperChain.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Mappers } from "./Mappers";
33
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./Typings";
44

55
const { Base64, Chunk, FromJSON, HexToFloat, HexToInt, Offset } = Mappers;
6+
// tslint:disable-next-line:no-var-requires
7+
const { version } = require("../package.json");
68

79
class MapperMock implements IMapper {
810
initParams: any = {};
@@ -71,14 +73,14 @@ describe("Data mapper chain", () => {
7173
dataMapperChain.mappers = [];
7274

7375
const serializedConfig = dataMapperChain.serializeConfig();
74-
expect(serializedConfig).toBe(`{"name":"Test","mappers":[]}`);
76+
expect(serializedConfig).toBe(`{"name":"Test","version":"${version}","mappers":[]}`);
7577
});
7678

7779
it("should correctly serialize with mapper", () => {
7880
dataMapperChain.addMapper(new MapperMock());
7981

8082
const serializedConfig = dataMapperChain.serializeConfig();
81-
expect(serializedConfig).toBe(`{"name":"","mappers":[{"id":"MOCK","params":{"p1":1,"p2":"2"}}]}`);
83+
expect(serializedConfig).toBe(`{"name":"","version":"${version}","mappers":[{"id":"MOCK","params":{"p1":1,"p2":"2"}}]}`);
8284
});
8385

8486
it("should correctly deserialize with no mappers", () => {

src/DataMapperChain.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IBase64Config, IChunkConfig, IFromJSONConfig, IHexToFloatConfig, IHexTo
22
import { AVAILABLE_MAPPERS_TYPES, Mappers } from "./Mappers";
33
import { IDataValue, IMapper, IMapperConfig, IMapperType } from "./Typings";
44

5+
const CURRENT_VERSION = "0.6.0";
56
const { Base64, Chunk, FromJSON, HexToFloat, HexToInt, Offset } = Mappers;
67

78
/**
@@ -63,6 +64,7 @@ export class DataMapperChain {
6364
serializeConfig(): string {
6465
return JSON.stringify({
6566
name: this.name,
67+
version: CURRENT_VERSION,
6668
mappers: this.mappers.map((mapper) => {
6769
return mapper.config();
6870
}),

0 commit comments

Comments
 (0)