CustomNodesModule.ts 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { ContainerModule, interfaces } from 'inversify';
  2. import { ServiceIdentifiers } from '../../ServiceIdentifiers';
  3. import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
  4. import { ICustomNodeGroup } from '../../../interfaces/custom-nodes/ICustomNodeGroup';
  5. import { IOptions } from '../../../interfaces/options/IOptions';
  6. import { CustomNodes } from '../../../enums/container/custom-nodes/CustomNodes';
  7. import { CustomNodeGroups } from '../../../enums/container/custom-nodes/CustomNodeGroups';
  8. import { ConsoleOutputCustomNodeGroup } from '../../../custom-nodes/console-output-nodes/group/ConsoleOutputCustomNodeGroup';
  9. import { DebugProtectionCustomNodeGroup } from '../../../custom-nodes/debug-protection-nodes/group/DebugProtectionCustomNodeGroup';
  10. import { DomainLockCustomNodeGroup } from '../../../custom-nodes/domain-lock-nodes/group/DomainLockCustomNodeGroup';
  11. import { SelfDefendingCustomNodeGroup } from '../../../custom-nodes/self-defending-nodes/group/SelfDefendingCustomNodeGroup';
  12. import { StringArrayCustomNodeGroup } from '../../../custom-nodes/string-array-nodes/group/StringArrayCustomNodeGroup';
  13. import { BinaryExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode';
  14. import { BlockStatementControlFlowFlatteningNode } from '../../../custom-nodes/control-flow-flattening-nodes/BlockStatementControlFlowFlatteningNode';
  15. import { CallExpressionControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/CallExpressionControlFlowStorageCallNode';
  16. import { CallExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/CallExpressionFunctionNode';
  17. import { ControlFlowStorageNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode';
  18. import { ConsoleOutputDisableExpressionNode } from '../../../custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode';
  19. import { DebugProtectionFunctionCallNode } from '../../../custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode';
  20. import { DebugProtectionFunctionIntervalNode } from '../../../custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode';
  21. import { DebugProtectionFunctionNode } from '../../../custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode';
  22. import { DomainLockNode } from '../../../custom-nodes/domain-lock-nodes/DomainLockNode';
  23. import { ExpressionWithOperatorControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode';
  24. import { LogicalExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode';
  25. import { NodeCallsControllerFunctionNode } from '../../../custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode';
  26. import { SelfDefendingUnicodeNode } from '../../../custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode';
  27. import { StringArrayCallsWrapper } from '../../../custom-nodes/string-array-nodes/StringArrayCallsWrapper';
  28. import { StringArrayNode } from '../../../custom-nodes/string-array-nodes/StringArrayNode';
  29. import { StringArrayRotateFunctionNode } from '../../../custom-nodes/string-array-nodes/StringArrayRotateFunctionNode';
  30. import { StringLiteralControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode';
  31. import { StringLiteralNode } from '../../../custom-nodes/control-flow-flattening-nodes/StringLiteralNode';
  32. export const customNodesModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
  33. // custom nodes
  34. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  35. .toConstructor(BinaryExpressionFunctionNode)
  36. .whenTargetNamed(CustomNodes.BinaryExpressionFunctionNode);
  37. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  38. .toConstructor(BlockStatementControlFlowFlatteningNode)
  39. .whenTargetNamed(CustomNodes.BlockStatementControlFlowFlatteningNode);
  40. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  41. .toConstructor(CallExpressionControlFlowStorageCallNode)
  42. .whenTargetNamed(CustomNodes.CallExpressionControlFlowStorageCallNode);
  43. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  44. .toConstructor(CallExpressionFunctionNode)
  45. .whenTargetNamed(CustomNodes.CallExpressionFunctionNode);
  46. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  47. .toConstructor(ControlFlowStorageNode)
  48. .whenTargetNamed(CustomNodes.ControlFlowStorageNode);
  49. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  50. .toConstructor(ConsoleOutputDisableExpressionNode)
  51. .whenTargetNamed(CustomNodes.ConsoleOutputDisableExpressionNode);
  52. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  53. .toConstructor(DebugProtectionFunctionCallNode)
  54. .whenTargetNamed(CustomNodes.DebugProtectionFunctionCallNode);
  55. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  56. .toConstructor(DebugProtectionFunctionIntervalNode)
  57. .whenTargetNamed(CustomNodes.DebugProtectionFunctionIntervalNode);
  58. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  59. .toConstructor(DebugProtectionFunctionNode)
  60. .whenTargetNamed(CustomNodes.DebugProtectionFunctionNode);
  61. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  62. .toConstructor(DomainLockNode)
  63. .whenTargetNamed(CustomNodes.DomainLockNode);
  64. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  65. .toConstructor(ExpressionWithOperatorControlFlowStorageCallNode)
  66. .whenTargetNamed(CustomNodes.ExpressionWithOperatorControlFlowStorageCallNode);
  67. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  68. .toConstructor(LogicalExpressionFunctionNode)
  69. .whenTargetNamed(CustomNodes.LogicalExpressionFunctionNode);
  70. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  71. .toConstructor(NodeCallsControllerFunctionNode)
  72. .whenTargetNamed(CustomNodes.NodeCallsControllerFunctionNode);
  73. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  74. .toConstructor(SelfDefendingUnicodeNode)
  75. .whenTargetNamed(CustomNodes.SelfDefendingUnicodeNode);
  76. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  77. .toConstructor(StringArrayCallsWrapper)
  78. .whenTargetNamed(CustomNodes.StringArrayCallsWrapper);
  79. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  80. .toConstructor(StringArrayNode)
  81. .whenTargetNamed(CustomNodes.StringArrayNode);
  82. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  83. .toConstructor(StringArrayRotateFunctionNode)
  84. .whenTargetNamed(CustomNodes.StringArrayRotateFunctionNode);
  85. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  86. .toConstructor(StringLiteralControlFlowStorageCallNode)
  87. .whenTargetNamed(CustomNodes.StringLiteralControlFlowStorageCallNode);
  88. bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
  89. .toConstructor(StringLiteralNode)
  90. .whenTargetNamed(CustomNodes.StringLiteralNode);
  91. // node groups
  92. bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
  93. .to(ConsoleOutputCustomNodeGroup)
  94. .whenTargetNamed(CustomNodeGroups.ConsoleOutputCustomNodeGroup);
  95. bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
  96. .to(DebugProtectionCustomNodeGroup)
  97. .whenTargetNamed(CustomNodeGroups.DebugProtectionCustomNodeGroup);
  98. bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
  99. .to(DomainLockCustomNodeGroup)
  100. .whenTargetNamed(CustomNodeGroups.DomainLockCustomNodeGroup);
  101. bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
  102. .to(SelfDefendingCustomNodeGroup)
  103. .whenTargetNamed(CustomNodeGroups.SelfDefendingCustomNodeGroup);
  104. bind<ICustomNodeGroup>(ServiceIdentifiers.ICustomNodeGroup)
  105. .to(StringArrayCustomNodeGroup)
  106. .whenTargetNamed(CustomNodeGroups.StringArrayCustomNodeGroup);
  107. // customNode factory
  108. bind<ICustomNode>(ServiceIdentifiers.Factory__ICustomNode)
  109. .toFactory<ICustomNode>((context: interfaces.Context) => {
  110. const cache: Map <CustomNodes, interfaces.Newable<ICustomNode>> = new Map();
  111. let cachedOptions: IOptions;
  112. return (customNodeName: CustomNodes) => {
  113. if (!cachedOptions) {
  114. cachedOptions = context.container.get<IOptions>(ServiceIdentifiers.IOptions);
  115. }
  116. if (cache.has(customNodeName)) {
  117. return new (<interfaces.Newable<ICustomNode>>cache.get(customNodeName));
  118. }
  119. const constructor: interfaces.Newable<ICustomNode> = context.container
  120. .getNamed<interfaces.Newable<ICustomNode>>(
  121. ServiceIdentifiers.Newable__ICustomNode,
  122. customNodeName
  123. );
  124. cache.set(customNodeName, constructor);
  125. return new constructor(cachedOptions);
  126. };
  127. });
  128. // customNodeGroup factory
  129. bind<ICustomNodeGroup>(ServiceIdentifiers.Factory__ICustomNodeGroup)
  130. .toFactory<ICustomNodeGroup>((context: interfaces.Context) => {
  131. return (customNodeGroupName: CustomNodeGroups) => {
  132. return context.container.getNamed<ICustomNodeGroup>(
  133. ServiceIdentifiers.ICustomNodeGroup,
  134. customNodeGroupName
  135. );
  136. };
  137. });
  138. });