All files / src/storages/custom-node-group CustomNodeGroupStorage.ts

95.24% Statements 20/21
50% Branches 1/2
100% Functions 2/2
94.44% Lines 17/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 701x 1x             1x   1x 1x     1x       1x                                                   6254x   6254x 6254x   6254x       6254x 6254x   6254x 31270x       31270x       31270x        
import { injectable, inject } from 'inversify';
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
import { TCustomNodeGroupFactory } from '../../types/container/TCustomNodeGroupFactory';
 
import { ICustomNodeGroup } from '../../interfaces/custom-nodes/ICustomNodeGroup';
import { IOptions } from '../../interfaces/options/IOptions';
 
import { CustomNodeGroups } from '../../enums/container/CustomNodeGroups';
 
import { MapStorage } from '../MapStorage';
import { RandomGeneratorUtils } from '../../utils/RandomGeneratorUtils';
 
@injectable()
export class CustomNodeGroupStorage extends MapStorage <ICustomNodeGroup> {
    /**
     * @type {CustomNodeGroups[]}
     */
    private static readonly customNodeGroupsList: CustomNodeGroups[] = [
        CustomNodeGroups.ConsoleOutputCustomNodeGroup,
        CustomNodeGroups.DebugProtectionCustomNodeGroup,
        CustomNodeGroups.DomainLockCustomNodeGroup,
        CustomNodeGroups.SelfDefendingCustomNodeGroup,
        CustomNodeGroups.StringArrayCustomNodeGroup
    ];
 
    /**
     * @type {TCustomNodesFactoriesFactory}
     */
    private readonly customNodeGroupFactory: TCustomNodeGroupFactory;
 
    /**
     * @type {IOptions}
     */
    private readonly options: IOptions;
 
    /**
     * @param customNodeGroupFactory
     * @param options
     */
    constructor (
        @inject(ServiceIdentifiers.Factory__ICustomNodeGroup) customNodeGroupFactory: TCustomNodeGroupFactory,
        @inject(ServiceIdentifiers.IOptions) options: IOptions
    ) {
        super();
 
        this.customNodeGroupFactory = customNodeGroupFactory;
        this.options = options;
 
        this.initialize();
    }
 
    public initialize (): void {
        this.storage = new Map <string, ICustomNodeGroup> ();
        this.storageId = RandomGeneratorUtils.getRandomString(6);
 
        CustomNodeGroupStorage.customNodeGroupsList.forEach((customNodeGroupName: CustomNodeGroups) => {
            const customNodeGroup: ICustomNodeGroup = this.customNodeGroupFactory(
                customNodeGroupName
            );
 
            Iif (!customNodeGroup) {
                return;
            }
 
            this.storage.set(customNodeGroupName, customNodeGroup);
        });
    }
}