|
@@ -10,14 +10,17 @@ import { IEncodedValue } from '../../interfaces/IEncodedValue';
|
|
import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
|
|
import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IOptions } from '../../interfaces/options/IOptions';
|
|
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
|
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
|
|
|
+import { IStringArrayStorage } from '../../interfaces/storages/string-array-storage/IStringArrayStorage';
|
|
import { IStringArrayStorageItemData } from '../../interfaces/storages/string-array-storage/IStringArrayStorageItem';
|
|
import { IStringArrayStorageItemData } from '../../interfaces/storages/string-array-storage/IStringArrayStorageItem';
|
|
|
|
|
|
|
|
+import { initializable } from '../../decorators/Initializable';
|
|
|
|
+
|
|
import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
|
|
import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
|
|
|
|
|
|
import { MapStorage } from '../MapStorage';
|
|
import { MapStorage } from '../MapStorage';
|
|
|
|
|
|
@injectable()
|
|
@injectable()
|
|
-export class StringArrayStorage extends MapStorage <string, IStringArrayStorageItemData> {
|
|
|
|
|
|
+export class StringArrayStorage extends MapStorage <string, IStringArrayStorageItemData> implements IStringArrayStorage {
|
|
/**
|
|
/**
|
|
* @type {number}
|
|
* @type {number}
|
|
*/
|
|
*/
|
|
@@ -58,6 +61,23 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
|
*/
|
|
*/
|
|
private readonly rc4Keys: string[];
|
|
private readonly rc4Keys: string[];
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @type {number}
|
|
|
|
+ */
|
|
|
|
+ private rotationAmount: number = 0;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @type {string}
|
|
|
|
+ */
|
|
|
|
+ @initializable()
|
|
|
|
+ private stringArrayStorageName!: string;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @type {string}
|
|
|
|
+ */
|
|
|
|
+ @initializable()
|
|
|
|
+ private stringArrayStorageCallsWrapperName!: string;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
|
|
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
|
|
* @param {IArrayUtils} arrayUtils
|
|
* @param {IArrayUtils} arrayUtils
|
|
@@ -99,10 +119,13 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
|
.generate(StringArrayStorage.stringArrayNameLength);
|
|
.generate(StringArrayStorage.stringArrayNameLength);
|
|
const baseStringArrayCallsWrapperName: string = this.identifierNamesGenerator
|
|
const baseStringArrayCallsWrapperName: string = this.identifierNamesGenerator
|
|
.generate(StringArrayStorage.stringArrayNameLength);
|
|
.generate(StringArrayStorage.stringArrayNameLength);
|
|
- const stringArrayName: string = `${this.options.identifiersPrefix}${baseStringArrayName}`;
|
|
|
|
- const stringArrayCallsWrapperName: string = `${this.options.identifiersPrefix}${baseStringArrayCallsWrapperName}`;
|
|
|
|
|
|
|
|
- this.storageId = `${stringArrayName}|${stringArrayCallsWrapperName}`;
|
|
|
|
|
|
+ this.stringArrayStorageName = `${this.options.identifiersPrefix}${baseStringArrayName}`;
|
|
|
|
+ this.stringArrayStorageCallsWrapperName = `${this.options.identifiersPrefix}${baseStringArrayCallsWrapperName}`;
|
|
|
|
+
|
|
|
|
+ this.rotationAmount = this.options.rotateStringArray
|
|
|
|
+ ? this.randomGenerator.getRandomInteger(100, 500)
|
|
|
|
+ : 0;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -114,26 +137,76 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param {number} rotationAmount
|
|
|
|
|
|
+ * @returns {number}
|
|
*/
|
|
*/
|
|
- public rotateStorage (rotationAmount: number): void {
|
|
|
|
|
|
+ public getRotationAmount (): number {
|
|
|
|
+ return this.rotationAmount;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
|
|
+ public getStorageId (): string {
|
|
|
|
+ return this.stringArrayStorageName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
|
|
+ public getStorageName (): string {
|
|
|
|
+ return this.getStorageId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
|
|
+ public getStorageCallsWrapperName (): string {
|
|
|
|
+ return this.stringArrayStorageCallsWrapperName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public rotateStorage (): void {
|
|
|
|
+ if (!this.getLength()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
this.storage = new Map(
|
|
this.storage = new Map(
|
|
this.arrayUtils.rotate(
|
|
this.arrayUtils.rotate(
|
|
Array.from(this.storage.entries()),
|
|
Array.from(this.storage.entries()),
|
|
- rotationAmount
|
|
|
|
|
|
+ this.rotationAmount
|
|
)
|
|
)
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public shuffleStorage (): void {
|
|
|
|
+ this.storage = new Map(
|
|
|
|
+ this.arrayUtils
|
|
|
|
+ .shuffle(Array.from(this.storage.entries()))
|
|
|
|
+ .map<[string, IStringArrayStorageItemData]>(
|
|
|
|
+ (
|
|
|
|
+ [value, stringArrayStorageItemData]: [string, IStringArrayStorageItemData],
|
|
|
|
+ index: number
|
|
|
|
+ ) => {
|
|
|
|
+ stringArrayStorageItemData.index = index;
|
|
|
|
+
|
|
|
|
+ return [value, stringArrayStorageItemData];
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ .sort((
|
|
|
|
+ [, stringArrayStorageItemDataA]: [string, IStringArrayStorageItemData],
|
|
|
|
+ [, stringArrayStorageItemDataB]: [string, IStringArrayStorageItemData]
|
|
|
|
+ ) => stringArrayStorageItemDataA.index - stringArrayStorageItemDataB.index)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
public toString (): string {
|
|
public toString (): string {
|
|
return Array
|
|
return Array
|
|
.from(this.storage.values())
|
|
.from(this.storage.values())
|
|
- .map((item: IStringArrayStorageItemData) => {
|
|
|
|
|
|
+ .map((stringArrayStorageItemData: IStringArrayStorageItemData) => {
|
|
return `'${this.escapeSequenceEncoder.encode(
|
|
return `'${this.escapeSequenceEncoder.encode(
|
|
- item.encodedValue,
|
|
|
|
|
|
+ stringArrayStorageItemData.encodedValue,
|
|
this.options.unicodeEscapeSequence
|
|
this.options.unicodeEscapeSequence
|
|
)}'`;
|
|
)}'`;
|
|
}).toString();
|
|
}).toString();
|