@contrail/transform-data 1.0.14 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { TransformTask } from "../processor";
|
|
2
2
|
export declare class MapFileUtil {
|
|
3
3
|
private entities;
|
|
4
|
-
private
|
|
4
|
+
private instanceCache;
|
|
5
|
+
private static STATIC_CACHE;
|
|
5
6
|
static FILE_NOT_FOUND: string;
|
|
6
7
|
static ERROR_RETRIEVING: string;
|
|
7
|
-
constructor(entities: any);
|
|
8
|
+
constructor(entities: any, useStaticCache?: boolean);
|
|
9
|
+
private getCache;
|
|
10
|
+
clearCache(): void;
|
|
8
11
|
getMapFile(fileId: string): Promise<any>;
|
|
9
12
|
getMappingSectionFromMap(mapFile: any, mapSectionKey: string, direction: string): {};
|
|
10
13
|
getFullMapSection(transformMapFile: string, mapSectionKey: string): Promise<any>;
|
|
11
14
|
getMappingSection(fileId: string, mapSectionKey: string, direction: string): Promise<{}>;
|
|
12
15
|
getMapKey(fileId: any, data: any, type: string, direction: string): Promise<string>;
|
|
13
|
-
static getTransformTasks(directionalMapSection: object): TransformTask[];
|
|
14
|
-
applyTransformMap(fileId: any, data: any, mapSectionKey: string, direction: string): Promise<any>;
|
|
16
|
+
static getTransformTasks(directionalMapSection: object, orderKey?: string): TransformTask[];
|
|
17
|
+
applyTransformMap(fileId: any, data: any, mapSectionKey: string, direction: string, transformTaskOrderKey?: any): Promise<any>;
|
|
15
18
|
}
|
|
@@ -3,16 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MapFileUtil = void 0;
|
|
4
4
|
const processor_1 = require("../processor");
|
|
5
5
|
class MapFileUtil {
|
|
6
|
-
constructor(entities) {
|
|
6
|
+
constructor(entities, useStaticCache = true) {
|
|
7
7
|
this.entities = entities;
|
|
8
|
-
|
|
8
|
+
if (!useStaticCache) {
|
|
9
|
+
this.instanceCache = {};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
getCache() {
|
|
13
|
+
return this.instanceCache || MapFileUtil.STATIC_CACHE;
|
|
14
|
+
}
|
|
15
|
+
clearCache() {
|
|
16
|
+
if (this.instanceCache) {
|
|
17
|
+
this.instanceCache = {};
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
MapFileUtil.STATIC_CACHE = {};
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
23
|
async getMapFile(fileId) {
|
|
11
24
|
if (!fileId) {
|
|
12
25
|
return {};
|
|
13
26
|
}
|
|
14
|
-
|
|
15
|
-
|
|
27
|
+
const cache = this.getCache();
|
|
28
|
+
if (cache[fileId]) {
|
|
29
|
+
return cache[fileId];
|
|
16
30
|
}
|
|
17
31
|
const options = {
|
|
18
32
|
entityName: 'file',
|
|
@@ -39,7 +53,7 @@ class MapFileUtil {
|
|
|
39
53
|
catch (e) {
|
|
40
54
|
throw new Error(MapFileUtil.ERROR_RETRIEVING + e);
|
|
41
55
|
}
|
|
42
|
-
|
|
56
|
+
cache[fileId] = mappingFile;
|
|
43
57
|
return mappingFile;
|
|
44
58
|
}
|
|
45
59
|
getMappingSectionFromMap(mapFile, mapSectionKey, direction) {
|
|
@@ -75,9 +89,9 @@ class MapFileUtil {
|
|
|
75
89
|
}
|
|
76
90
|
return undefined;
|
|
77
91
|
}
|
|
78
|
-
static getTransformTasks(directionalMapSection) {
|
|
92
|
+
static getTransformTasks(directionalMapSection, orderKey = 'transformOrder') {
|
|
79
93
|
const tasks = [];
|
|
80
|
-
const order = directionalMapSection[
|
|
94
|
+
const order = directionalMapSection[orderKey];
|
|
81
95
|
if (order) {
|
|
82
96
|
for (const step of order) {
|
|
83
97
|
const task = {
|
|
@@ -96,11 +110,11 @@ class MapFileUtil {
|
|
|
96
110
|
}
|
|
97
111
|
return tasks;
|
|
98
112
|
}
|
|
99
|
-
async applyTransformMap(fileId, data, mapSectionKey, direction) {
|
|
113
|
+
async applyTransformMap(fileId, data, mapSectionKey, direction, transformTaskOrderKey) {
|
|
100
114
|
if (fileId && data) {
|
|
101
115
|
const mapping = await this.getMappingSection(fileId, mapSectionKey, direction);
|
|
102
116
|
if (mapping) {
|
|
103
|
-
const tasks = MapFileUtil.getTransformTasks(mapping);
|
|
117
|
+
const tasks = MapFileUtil.getTransformTasks(mapping, transformTaskOrderKey);
|
|
104
118
|
if (tasks.length > 0) {
|
|
105
119
|
const convertedArray = processor_1.TransformProcessor.transformData([data], tasks);
|
|
106
120
|
data = convertedArray[0];
|
|
@@ -111,5 +125,6 @@ class MapFileUtil {
|
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
127
|
exports.MapFileUtil = MapFileUtil;
|
|
128
|
+
MapFileUtil.STATIC_CACHE = {};
|
|
114
129
|
MapFileUtil.FILE_NOT_FOUND = 'Mapping File not found for id: ';
|
|
115
130
|
MapFileUtil.ERROR_RETRIEVING = 'Error getting mapping file: ';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/transform-data",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Libraries for transforming data",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
10
10
|
"lint": "tslint --fix -p tsconfig.json",
|
|
11
|
-
"test": "jest"
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"test:watch": "jest --watch"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [],
|
|
14
15
|
"author": "",
|