Code coverage report for src/node-transformers/AbstractNodeTransformersFactory.ts

# All files / src/node-transformers AbstractNodeTransformersFactory.ts

12.5% Statements 1/8
0% Branches 0/2
0% Functions 0/2
12.5% Lines 1/8

    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

    1x

     import { TNodeTransformer } from '../types/TNodeTransformer';

    import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
    import { INodeTransformer } from '../interfaces/INodeTransformer';
    import { INodeTransformersFactory } from '../interfaces/INodeTransformersFactory';
    import { IOptions } from '../interfaces/IOptions';
    import { IStorage } from '../interfaces/IStorage';

    export abstract class AbstractNodeTransformersFactory implements INodeTransformersFactory {
        /**
         * @type {Map<string, TNodeTransformer[]>}
         */
        protected abstract readonly nodeTransformers: Map <string, TNodeTransformer[]>;

        /**
         * @type IStorage<ICustomNode>
         */
        protected readonly customNodesStorage: IStorage<ICustomNode>;

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

        /**
         * @param customNodesStorage
         * @param options
         */
        constructor (customNodesStorage: IStorage<ICustomNode>, options: IOptions) {
            this.customNodesStorage = customNodesStorage;
            this.options = options;
        }

        /**
         * @param nodeType
         * @returns {INodeTransformer[]}
         */
        public initializeNodeTransformers (nodeType: string): INodeTransformer[] {
            const nodeTransformers: TNodeTransformer[] = this.nodeTransformers.get(nodeType) || [];
            const instancesArray: INodeTransformer[] = [];

            nodeTransformers.forEach((transformer: TNodeTransformer) => {
                instancesArray.push(
                    new transformer(this.customNodesStorage, this.options)
                );
            });

            return instancesArray;
        }
    }