CustomNodeGroupStorage.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { inject, injectable, postConstruct } from 'inversify';
  2. import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
  3. import { TCustomNodeGroupFactory } from '../../types/container/custom-nodes/TCustomNodeGroupFactory';
  4. import { ICustomNodeGroup } from '../../interfaces/custom-nodes/ICustomNodeGroup';
  5. import { IOptions } from '../../interfaces/options/IOptions';
  6. import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
  7. import { CustomNodeGroup } from '../../enums/custom-nodes/CustomNodeGroup';
  8. import { MapStorage } from '../MapStorage';
  9. @injectable()
  10. export class CustomNodeGroupStorage extends MapStorage <ICustomNodeGroup> {
  11. /**
  12. * @type {CustomNodeGroup[]}
  13. */
  14. private static readonly customNodeGroupsList: CustomNodeGroup[] = [
  15. CustomNodeGroup.ConsoleOutputCustomNodeGroup,
  16. CustomNodeGroup.DebugProtectionCustomNodeGroup,
  17. CustomNodeGroup.DomainLockCustomNodeGroup,
  18. CustomNodeGroup.SelfDefendingCustomNodeGroup,
  19. CustomNodeGroup.StringArrayCustomNodeGroup
  20. ];
  21. /**
  22. * @type {TCustomNodesFactoriesFactory}
  23. */
  24. private readonly customNodeGroupFactory: TCustomNodeGroupFactory;
  25. /**
  26. * @param {TCustomNodeGroupFactory} customNodeGroupFactory
  27. * @param {IRandomGenerator} randomGenerator
  28. * @param {IOptions} options
  29. */
  30. constructor (
  31. @inject(ServiceIdentifiers.Factory__ICustomNodeGroup) customNodeGroupFactory: TCustomNodeGroupFactory,
  32. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  33. @inject(ServiceIdentifiers.IOptions) options: IOptions
  34. ) {
  35. super(randomGenerator, options);
  36. this.customNodeGroupFactory = customNodeGroupFactory;
  37. }
  38. @postConstruct()
  39. public initialize (): void {
  40. this.storage = new Map <string, ICustomNodeGroup>();
  41. this.storageId = this.randomGenerator.getRandomString(6);
  42. CustomNodeGroupStorage.customNodeGroupsList.forEach((customNodeGroupName: CustomNodeGroup) => {
  43. const customNodeGroup: ICustomNodeGroup = this.customNodeGroupFactory(
  44. customNodeGroupName
  45. );
  46. if (!customNodeGroup) {
  47. return;
  48. }
  49. this.storage.set(customNodeGroupName, customNodeGroup);
  50. });
  51. }
  52. }