import { ContainerModule, interfaces } from 'inversify'; import { ServiceIdentifiers } from '../../ServiceIdentifiers'; import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode'; import { ICustomNodeGroup } from '../../../interfaces/custom-nodes/ICustomNodeGroup'; import { IOptions } from '../../../interfaces/options/IOptions'; import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes'; import { CustomNodeGroups } from '../../../enums/container/custom-nodes/CustomNodeGroups'; import { ConsoleOutputCustomNodeGroup } from '../../../custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup'; import { DebugProtectionCustomNodeGroup } from '../../../custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup'; import { DomainLockCustomNodeGroup } from '../../../custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup'; import { SelfDefendingCustomNodeGroup } from '../../../custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup'; import { StringArrayCustomNodeGroup } from '../../../custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup'; import { BinaryExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode'; import { BlockStatementControlFlowFlatteningNode } from '../../../custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode'; import { CallExpressionControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode'; import { CallExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode'; import { ControlFlowStorageNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode'; import { ConsoleOutputDisableExpressionNode } from '../../../custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode'; import { DebugProtectionFunctionCallNode } from '../../../custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode'; import { DebugProtectionFunctionIntervalNode } from '../../../custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode'; import { DebugProtectionFunctionNode } from '../../../custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode'; import { DomainLockNode } from '../../../custom-nodes/domain-lock-nodes/DomainLockNode'; import { ExpressionWithOperatorControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode'; import { LogicalExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode'; import { NodeCallsControllerFunctionNode } from '../../../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode'; import { SelfDefendingUnicodeNode } from '../../../custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode'; import { StringArrayCallsWrapper } from '../../../custom-nodes/string-array-nodes/StringArrayCallsWrapper'; import { StringArrayNode } from '../../../custom-nodes/string-array-nodes/StringArrayNode'; import { StringArrayRotateFunctionNode } from '../../../custom-nodes/string-array-nodes/StringArrayRotateFunctionNode'; import { StringLiteralControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode'; import { StringLiteralNode } from '../../../custom-nodes/control-flow-flattening-nodes/StringLiteralNode'; export const customNodesModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // custom nodes bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(BinaryExpressionFunctionNode) .whenTargetNamed(CustomNodes.BinaryExpressionFunctionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(BlockStatementControlFlowFlatteningNode) .whenTargetNamed(CustomNodes.BlockStatementControlFlowFlatteningNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(CallExpressionControlFlowStorageCallNode) .whenTargetNamed(CustomNodes.CallExpressionControlFlowStorageCallNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(CallExpressionFunctionNode) .whenTargetNamed(CustomNodes.CallExpressionFunctionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(ControlFlowStorageNode) .whenTargetNamed(CustomNodes.ControlFlowStorageNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(ConsoleOutputDisableExpressionNode) .whenTargetNamed(CustomNodes.ConsoleOutputDisableExpressionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(DebugProtectionFunctionCallNode) .whenTargetNamed(CustomNodes.DebugProtectionFunctionCallNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(DebugProtectionFunctionIntervalNode) .whenTargetNamed(CustomNodes.DebugProtectionFunctionIntervalNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(DebugProtectionFunctionNode) .whenTargetNamed(CustomNodes.DebugProtectionFunctionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(DomainLockNode) .whenTargetNamed(CustomNodes.DomainLockNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(ExpressionWithOperatorControlFlowStorageCallNode) .whenTargetNamed(CustomNodes.ExpressionWithOperatorControlFlowStorageCallNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(LogicalExpressionFunctionNode) .whenTargetNamed(CustomNodes.LogicalExpressionFunctionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(NodeCallsControllerFunctionNode) .whenTargetNamed(CustomNodes.NodeCallsControllerFunctionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(SelfDefendingUnicodeNode) .whenTargetNamed(CustomNodes.SelfDefendingUnicodeNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(StringArrayCallsWrapper) .whenTargetNamed(CustomNodes.StringArrayCallsWrapper); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(StringArrayNode) .whenTargetNamed(CustomNodes.StringArrayNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(StringArrayRotateFunctionNode) .whenTargetNamed(CustomNodes.StringArrayRotateFunctionNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(StringLiteralControlFlowStorageCallNode) .whenTargetNamed(CustomNodes.StringLiteralControlFlowStorageCallNode); bind>(ServiceIdentifiers.Newable__ICustomNode) .toConstructor(StringLiteralNode) .whenTargetNamed(CustomNodes.StringLiteralNode); // node groups bind(ServiceIdentifiers.ICustomNodeGroup) .to(ConsoleOutputCustomNodeGroup) .whenTargetNamed(CustomNodeGroups.ConsoleOutputCustomNodeGroup); bind(ServiceIdentifiers.ICustomNodeGroup) .to(DebugProtectionCustomNodeGroup) .whenTargetNamed(CustomNodeGroups.DebugProtectionCustomNodeGroup); bind(ServiceIdentifiers.ICustomNodeGroup) .to(DomainLockCustomNodeGroup) .whenTargetNamed(CustomNodeGroups.DomainLockCustomNodeGroup); bind(ServiceIdentifiers.ICustomNodeGroup) .to(SelfDefendingCustomNodeGroup) .whenTargetNamed(CustomNodeGroups.SelfDefendingCustomNodeGroup); bind(ServiceIdentifiers.ICustomNodeGroup) .to(StringArrayCustomNodeGroup) .whenTargetNamed(CustomNodeGroups.StringArrayCustomNodeGroup); // customNode factory bind(ServiceIdentifiers.Factory__ICustomNode) .toFactory((context: interfaces.Context) => { const cache: Map > = new Map(); let cachedOptions: IOptions; return (customNodeName: CustomNodes) => { if (!cachedOptions) { cachedOptions = context.container.get(ServiceIdentifiers.IOptions); } if (cache.has(customNodeName)) { return new (>cache.get(customNodeName)); } const constructor: interfaces.Newable = context.container .getNamed>( ServiceIdentifiers.Newable__ICustomNode, customNodeName ); cache.set(customNodeName, constructor); return new constructor(cachedOptions); }; }); // customNodeGroup factory bind(ServiceIdentifiers.Factory__ICustomNodeGroup) .toFactory((context: interfaces.Context) => { return (customNodeGroupName: CustomNodeGroups) => { return context.container.getNamed( ServiceIdentifiers.ICustomNodeGroup, customNodeGroupName ); }; }); });