@contrail/transform-data 1.0.15 → 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,10 +1,13 @@
1
1
  import { TransformTask } from "../processor";
2
2
  export declare class MapFileUtil {
3
3
  private entities;
4
- private cache;
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>;
@@ -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
- this.cache = {};
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
- if (this.cache[fileId]) {
15
- return this.cache[fileId];
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
- this.cache[fileId] = mappingFile;
56
+ cache[fileId] = mappingFile;
43
57
  return mappingFile;
44
58
  }
45
59
  getMappingSectionFromMap(mapFile, mapSectionKey, direction) {
@@ -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.0.15",
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",