From 442cd7b56b7e52921e9daa2cde02d15e08b2fef4 Mon Sep 17 00:00:00 2001 From: sanex Date: Sun, 30 May 2021 13:19:22 +0300 Subject: [PATCH] Renamed `getAsDictionary` method of IMapStorage to the `getStorageAsDictionary`. Added tests. --- src/cli/utils/IdentifierNamesCacheUtils.ts | 2 +- src/interfaces/options/IOptions.ts | 2 +- .../source-code/IObfuscationResult.ts | 2 +- src/interfaces/storages/IMapStorage.ts | 10 ++++----- .../IIdentifierNamesCacheStorage.ts | 2 +- src/options/Options.ts | 2 +- src/source-code/ObfuscationResult.ts | 2 +- src/storages/MapStorage.ts | 14 ++++++------- .../IdentifierNamesCacheStorage.ts | 4 ++-- .../TIdentifierNamesCache.ts | 0 test/unit-tests/storages/MapStorage.spec.ts | 21 +++++++++++++++++++ 11 files changed, 41 insertions(+), 20 deletions(-) rename src/types/{caches => storages}/TIdentifierNamesCache.ts (100%) diff --git a/src/cli/utils/IdentifierNamesCacheUtils.ts b/src/cli/utils/IdentifierNamesCacheUtils.ts index 94e50aa5..e1437b63 100644 --- a/src/cli/utils/IdentifierNamesCacheUtils.ts +++ b/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'; diff --git a/src/interfaces/options/IOptions.ts b/src/interfaces/options/IOptions.ts index e2fde3e8..9284d370 100644 --- a/src/interfaces/options/IOptions.ts +++ b/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'; diff --git a/src/interfaces/source-code/IObfuscationResult.ts b/src/interfaces/source-code/IObfuscationResult.ts index 1c8dfab9..0597e91a 100644 --- a/src/interfaces/source-code/IObfuscationResult.ts +++ b/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]> { diff --git a/src/interfaces/storages/IMapStorage.ts b/src/interfaces/storages/IMapStorage.ts index 2b141524..50f004ca 100644 --- a/src/interfaces/storages/IMapStorage.ts +++ b/src/interfaces/storages/IMapStorage.ts @@ -9,11 +9,6 @@ export interface IMapStorage extends IInitializable { */ get (key: K): V | undefined; - /** - * @returns {TDictionary} - */ - getAsDictionary (): TDictionary; - /** * @param {K} key * @returns {V} @@ -36,6 +31,11 @@ export interface IMapStorage extends IInitializable { */ getStorage (): Map ; + /** + * @returns {TDictionary} + */ + getStorageAsDictionary (): TDictionary; + /** * @returns string */ diff --git a/src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts b/src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts index 99306e46..979537a1 100644 --- a/src/interfaces/storages/identifier-names-cache/IIdentifierNamesCacheStorage.ts +++ b/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'; diff --git a/src/options/Options.ts b/src/options/Options.ts index 79fbf3d4..bfed3f3c 100644 --- a/src/options/Options.ts +++ b/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'; diff --git a/src/source-code/ObfuscationResult.ts b/src/source-code/ObfuscationResult.ts index 19af5307..1a8843bb 100644 --- a/src/source-code/ObfuscationResult.ts +++ b/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'; diff --git a/src/storages/MapStorage.ts b/src/storages/MapStorage.ts index 853c5a2f..cc9b8842 100644 --- a/src/storages/MapStorage.ts +++ b/src/storages/MapStorage.ts @@ -58,13 +58,6 @@ export abstract class MapStorage implements IMapStorage { return this.storage.get(key); } - /** - * @returns {TDictionary} - */ - public getAsDictionary (): TDictionary { - return Object.fromEntries(this.storage); - } - /** * @param {K} key * @returns {V} @@ -107,6 +100,13 @@ export abstract class MapStorage implements IMapStorage { return this.storage; } + /** + * @returns {TDictionary} + */ + public getStorageAsDictionary (): TDictionary { + return Object.fromEntries(this.storage); + } + /** * @returns {string} */ diff --git a/src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts b/src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts index 3aff4059..0b466545 100644 --- a/src/storages/identifier-names-cache/IdentifierNamesCacheStorage.ts +++ b/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 imp return null; } - return this.getAsDictionary(); + return this.getStorageAsDictionary(); } } diff --git a/src/types/caches/TIdentifierNamesCache.ts b/src/types/storages/TIdentifierNamesCache.ts similarity index 100% rename from src/types/caches/TIdentifierNamesCache.ts rename to src/types/storages/TIdentifierNamesCache.ts diff --git a/test/unit-tests/storages/MapStorage.spec.ts b/test/unit-tests/storages/MapStorage.spec.ts index 488741e2..96e2a79c 100644 --- a/test/unit-tests/storages/MapStorage.spec.ts +++ b/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 = { + [storageKey]: storageValue + }; + + let storageAsDictionary: TDictionary; + + before(() => { + storage = getStorageInstance(); + 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;