All files / src/storages/custom-nodes CustomNodesStorage.ts

100% Statements 21/21
100% Branches 2/2
100% Functions 2/2
100% Lines 20/20
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 641x 1x               1x 1x 1x 1x 1x 1x   1x 1x       1x                                 2622x   2622x           2619x   2619x 13095x       13095x 11543x     1552x     2619x      
import { injectable, inject } from 'inversify';
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
import { TCustomNodesFactory } from '../../types/container/TCustomNodesFactory';
 
import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
import { IOptions } from '../../interfaces/options/IOptions';
import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData';
 
import { ConsoleOutputCustomNodesFactory } from '../../custom-nodes/console-output-nodes/factory/ConsoleOutputCustomNodesFactory';
import { DebugProtectionCustomNodesFactory } from '../../custom-nodes/debug-protection-nodes/factory/DebugProtectionCustomNodesFactory';
import { DomainLockCustomNodesFactory } from '../../custom-nodes/domain-lock-nodes/factory/DomainLockCustomNodesFactory';
import { MapStorage } from '../MapStorage';
import { SelfDefendingCustomNodesFactory } from '../../custom-nodes/self-defending-nodes/factory/SelfDefendingCustomNodesFactory';
import { StringArrayCustomNodesFactory } from '../../custom-nodes/string-array-nodes/factory/StringArrayCustomNodesFactory';
 
@injectable()
export class CustomNodesStorage extends MapStorage <ICustomNode> {
    /**
     * @type {TCustomNodesFactory[]}
     */
    private static readonly customNodesFactories: TCustomNodesFactory[] = [
        DomainLockCustomNodesFactory,
        SelfDefendingCustomNodesFactory,
        ConsoleOutputCustomNodesFactory,
        DebugProtectionCustomNodesFactory,
        StringArrayCustomNodesFactory
    ];
 
    /**
     * @type {IOptions}
     */
    private readonly options: IOptions;
 
    /**
     * @param options
     */
    constructor (@inject(ServiceIdentifiers.IOptions) options: IOptions) {
        super();
 
        this.options = options;
    }
    /**
     * @param stackTraceData
     */
    public initialize (stackTraceData: IStackTraceData[]): void {
        const customNodes: [string, ICustomNode][] = [];
 
        CustomNodesStorage.customNodesFactories.forEach((customNodesFactoryConstructor: TCustomNodesFactory) => {
            const customNodesFactory: Map <string, ICustomNode> | undefined = new customNodesFactoryConstructor(
                this.options
            ).initializeCustomNodes(stackTraceData);
 
            if (!customNodesFactory) {
                return;
            }
 
            customNodes.push(...customNodesFactory);
        });
 
        this.storage = new Map <string, ICustomNode> (customNodes);
    }
}