StoragesModule.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { ContainerModule, interfaces } from 'inversify';
  2. import { ServiceIdentifiers } from '../../ServiceIdentifiers';
  3. import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
  4. import { TCustomCodeHelperGroupStorage } from '../../../types/storages/TCustomCodeHelperGroupStorage';
  5. import { ILiteralNodesCacheStorage } from '../../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage';
  6. import { IOptions } from '../../../interfaces/options/IOptions';
  7. import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
  8. import { IStringArrayStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayStorage';
  9. import { ControlFlowStorage } from '../../../storages/custom-nodes/ControlFlowStorage';
  10. import { CustomCodeHelperGroupStorage } from '../../../storages/custom-code-helpers/CustomCodeHelperGroupStorage';
  11. import { LiteralNodesCacheStorage } from '../../../storages/string-array-transformers/LiteralNodesCacheStorage';
  12. import { StringArrayStorage } from '../../../storages/string-array-transformers/StringArrayStorage';
  13. export const storagesModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
  14. // storages
  15. bind<TCustomCodeHelperGroupStorage>(ServiceIdentifiers.TCustomNodeGroupStorage)
  16. .to(CustomCodeHelperGroupStorage)
  17. .inSingletonScope();
  18. bind<ILiteralNodesCacheStorage>(ServiceIdentifiers.ILiteralNodesCacheStorage)
  19. .to(LiteralNodesCacheStorage)
  20. .inSingletonScope();
  21. bind<IStringArrayStorage>(ServiceIdentifiers.IStringArrayStorage)
  22. .to(StringArrayStorage)
  23. .inSingletonScope();
  24. bind<interfaces.Newable<TControlFlowStorage>>(ServiceIdentifiers.Newable__TControlFlowStorage)
  25. .toConstructor(ControlFlowStorage);
  26. // controlFlowStorage factory
  27. bind<TControlFlowStorage>(ServiceIdentifiers.Factory__TControlFlowStorage)
  28. .toFactory<TControlFlowStorage>((context: interfaces.Context) => {
  29. return (): TControlFlowStorage => {
  30. const constructor: interfaces.Newable<TControlFlowStorage> = context.container
  31. .get<interfaces.Newable<TControlFlowStorage>>(ServiceIdentifiers.Newable__TControlFlowStorage);
  32. const randomGenerator: IRandomGenerator = context.container
  33. .get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator);
  34. const options: IOptions = context.container
  35. .get<IOptions>(ServiceIdentifiers.IOptions);
  36. const storage: TControlFlowStorage = new constructor(randomGenerator, options);
  37. storage.initialize();
  38. return storage;
  39. };
  40. });
  41. });