瀏覽代碼

Renamed `getAsDictionary` method of IMapStorage to the `getStorageAsDictionary`. Added tests.

sanex 4 年之前
父節點
當前提交
442cd7b56b

+ 1 - 1
src/cli/utils/IdentifierNamesCacheUtils.ts

@@ -1,7 +1,7 @@
 import * as fs from 'fs';
 import * as path from 'path';
 
-import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
 
 import { IFileData } from '../../interfaces/cli/IFileData';
 

+ 1 - 1
src/interfaces/options/IOptions.ts

@@ -1,4 +1,4 @@
-import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
 import { TOptionsPreset } from '../../types/options/TOptionsPreset';
 import { TStringArrayIndexesType } from '../../types/options/TStringArrayIndexesType';
 import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';

+ 1 - 1
src/interfaces/source-code/IObfuscationResult.ts

@@ -1,4 +1,4 @@
-import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
 import { IInitializable } from '../IInitializable';
 
 export interface IObfuscationResult extends IInitializable <[string, string]> {

+ 5 - 5
src/interfaces/storages/IMapStorage.ts

@@ -9,11 +9,6 @@ export interface IMapStorage <K, V> extends IInitializable {
      */
     get (key: K): V | undefined;
 
-    /**
-     * @returns {TDictionary<V>}
-     */
-    getAsDictionary (): TDictionary<V>;
-
     /**
      * @param {K} key
      * @returns {V}
@@ -36,6 +31,11 @@ export interface IMapStorage <K, V> extends IInitializable {
      */
     getStorage (): Map <K, V>;
 
+    /**
+     * @returns {TDictionary<V>}
+     */
+    getStorageAsDictionary (): TDictionary<V>;
+
     /**
      * @returns string
      */

+ 1 - 1
src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts

@@ -1,4 +1,4 @@
-import { TIdentifierNamesCache } from '../../../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../../types/storages/TIdentifierNamesCache';
 
 import { IMapStorage } from '../IMapStorage';
 

+ 1 - 1
src/options/Options.ts

@@ -18,7 +18,7 @@ import {
     ValidatorOptions
 } from 'class-validator';
 
-import { TIdentifierNamesCache } from '../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../types/storages/TIdentifierNamesCache';
 import { TInputOptions } from '../types/options/TInputOptions';
 import { TOptionsPreset } from '../types/options/TOptionsPreset';
 import { TRenamePropertiesMode } from '../types/options/TRenamePropertiesMode';

+ 1 - 1
src/source-code/ObfuscationResult.ts

@@ -1,7 +1,7 @@
 import { inject, injectable } from 'inversify';
 import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
 
-import { TIdentifierNamesCache } from '../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../types/storages/TIdentifierNamesCache';
 
 import { ICryptUtils } from '../interfaces/utils/ICryptUtils';
 import { IIdentifierNamesCacheStorage } from '../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';

+ 7 - 7
src/storages/MapStorage.ts

@@ -58,13 +58,6 @@ export abstract class MapStorage <K, V> implements IMapStorage <K, V> {
         return this.storage.get(key);
     }
 
-    /**
-     * @returns {TDictionary<V>}
-     */
-    public getAsDictionary (): TDictionary<V> {
-        return Object.fromEntries(this.storage);
-    }
-
     /**
      * @param {K} key
      * @returns {V}
@@ -107,6 +100,13 @@ export abstract class MapStorage <K, V> implements IMapStorage <K, V> {
         return this.storage;
     }
 
+    /**
+     * @returns {TDictionary<V>}
+     */
+    public getStorageAsDictionary (): TDictionary<V> {
+        return Object.fromEntries(this.storage);
+    }
+
     /**
      * @returns {string}
      */

+ 2 - 2
src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts

@@ -1,7 +1,7 @@
 import { inject, injectable, postConstruct } from 'inversify';
 import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
-import { TIdentifierNamesCache } from '../../types/caches/TIdentifierNamesCache';
+import { TIdentifierNamesCache } from '../../types/storages/TIdentifierNamesCache';
 
 import { IIdentifierNamesCacheStorage } from '../../interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage';
 import { IOptions } from '../../interfaces/options/IOptions';
@@ -82,6 +82,6 @@ export class IdentifierNamesCacheStorage extends MapStorage <string, string> imp
             return null;
         }
 
-        return this.getAsDictionary();
+        return this.getStorageAsDictionary();
     }
 }

+ 0 - 0
src/types/caches/TIdentifierNamesCache.ts → src/types/storages/TIdentifierNamesCache.ts


+ 21 - 0
test/unit-tests/storages/MapStorage.spec.ts

@@ -4,6 +4,8 @@ import { assert } from 'chai';
 
 import { ServiceIdentifiers } from '../../../src/container/ServiceIdentifiers';
 
+import { TDictionary } from '../../../src/types/TDictionary';
+
 import { IInversifyContainerFacade } from '../../../src/interfaces/container/IInversifyContainerFacade';
 import { IMapStorage } from '../../../src/interfaces/storages/IMapStorage';
 import { IOptions } from '../../../src/interfaces/options/IOptions';
@@ -212,6 +214,25 @@ describe('MapStorage', () => {
         });
     });
 
+    describe('getStorageAsDictionary', () => {
+        const expectedDictionary: TDictionary<string> = {
+            [storageKey]: storageValue
+        };
+
+        let storageAsDictionary: TDictionary<string>;
+
+        before(() => {
+            storage = getStorageInstance<string>();
+            storage.set(storageKey, storageValue);
+
+            storageAsDictionary = storage.getStorageAsDictionary();
+        });
+
+        it('should return storage as dictionary', () => {
+            assert.deepEqual(storageAsDictionary, expectedDictionary);
+        });
+    });
+
     describe('has', () => {
         describe('Variant #1: item is presenting in storage', () => {
             const expectedItemExistence: boolean = true;