# All files / src/storages/custom-nodes CustomNodeGroupsStorage.ts

90.91% Statements 20/22
40% Branches 4/10
100% Functions 2/2
90.48% Lines 19/21

    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    1011x
    1x

    1x

    1x

    1x
    1x

    1x

    1606x

    1606x
    1606x

    1603x

    1603x
    8015x

    8015x
    6971x

    1044x

    1603x

    65112x

    1603x

     import { injectable, inject } from 'inversify';
    import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';

    import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
    import { IOptions } from '../../interfaces/options/IOptions';
    import { IStackTraceData } from '../../interfaces/stack-trace-analyzer/IStackTraceData';

    import { CustomNodesFactories } from '../../enums/container/CustomNodesFactories';

    import { MapStorage } from '../MapStorage';
    import { TCustomNodesFactoriesFactory } from '../../types/container/TCustomNodesFactoriesFactory';

    @injectable()
    export class CustomNodesStorage extends MapStorage <ICustomNode> {
        /**
         * @type {CustomNodesFactories[]}
         */
        private static readonly customNodesFactoriesList: CustomNodesFactories[] = [
            CustomNodesFactories.ConsoleOutputCustomNodesFactory,
            CustomNodesFactories.DebugProtectionCustomNodesFactory,
            CustomNodesFactories.DomainLockCustomNodesFactory,
            CustomNodesFactories.SelfDefendingCustomNodesFactory,
            CustomNodesFactories.StringArrayCustomNodesFactory
        ];

        /**
         * @type {TCustomNodesFactoriesFactory}
         */
        private readonly customNodesFactoriesFactory: TCustomNodesFactoriesFactory;

        /**
         * @type {IOptions}
         */
        private readonly options: IOptions;

        /**
         * @param customNodesFactoriesFactory
         * @param options
         */
        constructor (
            @inject(ServiceIdentifiers['Factory<ICustomNodesFactory>']) customNodesFactoriesFactory: TCustomNodesFactoriesFactory,
            @inject(ServiceIdentifiers.IOptions) options: IOptions
        ) {
            super();

            this.customNodesFactoriesFactory = customNodesFactoriesFactory;
            this.options = options;
        }

        /**
         * @param stackTraceData
         */
        public initialize (stackTraceData: IStackTraceData[]): void {
            const customNodes: [string, ICustomNode][] = [];

            CustomNodesStorage.customNodesFactoriesList.forEach((customNodesFactoryName: CustomNodesFactories) => {
                const customNodesFactory: Map <string, ICustomNode> | undefined = this.customNodesFactoriesFactory(
                    customNodesFactoryName
                ).initializeCustomNodes(stackTraceData);

                if (!customNodesFactory) {
                    return;
                }

                customNodes.push(...customNodesFactory);
            });

            this.storage = new Map <string, ICustomNode> (customNodes);
        }

        /**
         * @param key
         * @returns {ICustomNode}
         */
        public get (key: string | number): ICustomNode {
            return super.get(key);
        }

        /**
         * @param value
         * @returns {string | number | null}
         */
        public getKeyOf (value: ICustomNode): string | number | null {
            return super.getKeyOf(value);
        }

        /**
         * @returns {number}
         */
        public getLength (): number {
            return super.getLength();
        }

        /**
         * @returns {Map <string | number, ICustomNode>}
         */
        public getStorage (): Map <string | number, ICustomNode> {
            return super.getStorage();
        }
    }