DebugProtectionFunctionCallNode.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { inject, injectable, } from 'inversify';
  2. import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
  3. import * as format from 'string-template';
  4. import { TIdentifierNameGeneratorFactory } from '../../types/container/generators/TIdentifierNameGeneratorFactory';
  5. import { TStatement } from '../../types/node/TStatement';
  6. import { IOptions } from '../../interfaces/options/IOptions';
  7. import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
  8. import { initializable } from '../../decorators/Initializable';
  9. import { DebugProtectionFunctionCallTemplate } from '../../templates/debug-protection-nodes/debug-protection-function-call-node/DebugProtectionFunctionCallTemplate';
  10. import { AbstractCustomNode } from '../AbstractCustomNode';
  11. import { NodeUtils } from '../../node/NodeUtils';
  12. @injectable()
  13. export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
  14. /**
  15. * @type {string}
  16. */
  17. @initializable()
  18. private callsControllerFunctionName: string;
  19. /**
  20. * @type {string}
  21. */
  22. @initializable()
  23. private debugProtectionFunctionName: string;
  24. /**
  25. * @param {TIdentifierNameGeneratorFactory} identifierNameGeneratorFactory
  26. * @param {IRandomGenerator} randomGenerator
  27. * @param {IOptions} options
  28. */
  29. constructor (
  30. @inject(ServiceIdentifiers.Factory__IIdentifierNameGenerator)
  31. identifierNameGeneratorFactory: TIdentifierNameGeneratorFactory,
  32. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  33. @inject(ServiceIdentifiers.IOptions) options: IOptions
  34. ) {
  35. super(identifierNameGeneratorFactory, randomGenerator, options);
  36. }
  37. /**
  38. * @param {string} debugProtectionFunctionName
  39. * @param {string} callsControllerFunctionName
  40. */
  41. public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void {
  42. this.debugProtectionFunctionName = debugProtectionFunctionName;
  43. this.callsControllerFunctionName = callsControllerFunctionName;
  44. }
  45. /**
  46. * @returns {TStatement[]}
  47. */
  48. protected getNodeStructure (): TStatement[] {
  49. return NodeUtils.convertCodeToStructure(this.getTemplate());
  50. }
  51. /**
  52. * @returns {string}
  53. */
  54. protected getTemplate (): string {
  55. return format(DebugProtectionFunctionCallTemplate(), {
  56. debugProtectionFunctionName: this.debugProtectionFunctionName,
  57. singleNodeCallControllerFunctionName: this.callsControllerFunctionName
  58. });
  59. }
  60. }