DebugProtectionFunctionCallCodeHelper.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { inject, injectable, } from 'inversify';
  2. import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
  3. import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
  4. import { TStatement } from '../../types/node/TStatement';
  5. import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
  6. import { ICustomCodeHelperObfuscator } from '../../interfaces/custom-code-helpers/ICustomCodeHelperObfuscator';
  7. import { IOptions } from '../../interfaces/options/IOptions';
  8. import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
  9. import { initializable } from '../../decorators/Initializable';
  10. import { DebugProtectionFunctionCallTemplate } from './templates/debug-protection-function-call/DebugProtectionFunctionCallTemplate';
  11. import { AbstractCustomCodeHelper } from '../AbstractCustomCodeHelper';
  12. import { NodeUtils } from '../../node/NodeUtils';
  13. @injectable()
  14. export class DebugProtectionFunctionCallCodeHelper extends AbstractCustomCodeHelper {
  15. /**
  16. * @type {string}
  17. */
  18. @initializable()
  19. private callsControllerFunctionName!: string;
  20. /**
  21. * @type {string}
  22. */
  23. @initializable()
  24. private debugProtectionFunctionName!: string;
  25. /**
  26. * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
  27. * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
  28. * @param {ICustomCodeHelperObfuscator} customCodeHelperObfuscator
  29. * @param {IRandomGenerator} randomGenerator
  30. * @param {IOptions} options
  31. */
  32. public constructor (
  33. @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
  34. identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
  35. @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
  36. @inject(ServiceIdentifiers.ICustomCodeHelperObfuscator) customCodeHelperObfuscator: ICustomCodeHelperObfuscator,
  37. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  38. @inject(ServiceIdentifiers.IOptions) options: IOptions
  39. ) {
  40. super(
  41. identifierNamesGeneratorFactory,
  42. customCodeHelperFormatter,
  43. customCodeHelperObfuscator,
  44. randomGenerator,
  45. options
  46. );
  47. }
  48. /**
  49. * @param {string} debugProtectionFunctionName
  50. * @param {string} callsControllerFunctionName
  51. */
  52. public initialize (debugProtectionFunctionName: string, callsControllerFunctionName: string): void {
  53. this.debugProtectionFunctionName = debugProtectionFunctionName;
  54. this.callsControllerFunctionName = callsControllerFunctionName;
  55. }
  56. /**
  57. * @param {string} codeHelperTemplate
  58. * @returns {TStatement[]}
  59. */
  60. protected getNodeStructure (codeHelperTemplate: string): TStatement[] {
  61. return NodeUtils.convertCodeToStructure(codeHelperTemplate);
  62. }
  63. /**
  64. * @returns {string}
  65. */
  66. protected getCodeHelperTemplate (): string {
  67. return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionCallTemplate(), {
  68. debugProtectionFunctionName: this.debugProtectionFunctionName,
  69. callControllerFunctionName: this.callsControllerFunctionName
  70. });
  71. }
  72. }