ParsePubSub.js 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ParsePubSub = void 0;
  6. var _AdapterLoader = require("../Adapters/AdapterLoader");
  7. var _EventEmitterPubSub = require("../Adapters/PubSub/EventEmitterPubSub");
  8. var _RedisPubSub = require("../Adapters/PubSub/RedisPubSub");
  9. const ParsePubSub = exports.ParsePubSub = {};
  10. function useRedis(config) {
  11. const redisURL = config.redisURL;
  12. return typeof redisURL !== 'undefined' && redisURL !== '';
  13. }
  14. ParsePubSub.createPublisher = function (config) {
  15. if (useRedis(config)) {
  16. return _RedisPubSub.RedisPubSub.createPublisher(config);
  17. } else {
  18. const adapter = (0, _AdapterLoader.loadAdapter)(config.pubSubAdapter, _EventEmitterPubSub.EventEmitterPubSub, config);
  19. if (typeof adapter.createPublisher !== 'function') {
  20. throw 'pubSubAdapter should have createPublisher()';
  21. }
  22. return adapter.createPublisher(config);
  23. }
  24. };
  25. ParsePubSub.createSubscriber = function (config) {
  26. if (useRedis(config)) {
  27. return _RedisPubSub.RedisPubSub.createSubscriber(config);
  28. } else {
  29. const adapter = (0, _AdapterLoader.loadAdapter)(config.pubSubAdapter, _EventEmitterPubSub.EventEmitterPubSub, config);
  30. if (typeof adapter.createSubscriber !== 'function') {
  31. throw 'pubSubAdapter should have createSubscriber()';
  32. }
  33. return adapter.createSubscriber(config);
  34. }
  35. };
  36. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfQWRhcHRlckxvYWRlciIsInJlcXVpcmUiLCJfRXZlbnRFbWl0dGVyUHViU3ViIiwiX1JlZGlzUHViU3ViIiwiUGFyc2VQdWJTdWIiLCJleHBvcnRzIiwidXNlUmVkaXMiLCJjb25maWciLCJyZWRpc1VSTCIsImNyZWF0ZVB1Ymxpc2hlciIsIlJlZGlzUHViU3ViIiwiYWRhcHRlciIsImxvYWRBZGFwd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