ParseCloudCodePublisher.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ParseCloudCodePublisher = void 0;
  6. var _ParsePubSub = require("./ParsePubSub");
  7. var _node = _interopRequireDefault(require("parse/node"));
  8. var _logger = _interopRequireDefault(require("../logger"));
  9. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  10. class ParseCloudCodePublisher {
  11. // config object of the publisher, right now it only contains the redisURL,
  12. // but we may extend it later.
  13. constructor(config = {}) {
  14. this.parsePublisher = _ParsePubSub.ParsePubSub.createPublisher(config);
  15. }
  16. async connect() {
  17. if (typeof this.parsePublisher.connect === 'function') {
  18. if (this.parsePublisher.isOpen) {
  19. return;
  20. }
  21. return Promise.resolve(this.parsePublisher.connect());
  22. }
  23. }
  24. onCloudCodeAfterSave(request) {
  25. this._onCloudCodeMessage(_node.default.applicationId + 'afterSave', request);
  26. }
  27. onCloudCodeAfterDelete(request) {
  28. this._onCloudCodeMessage(_node.default.applicationId + 'afterDelete', request);
  29. }
  30. onClearCachedRoles(user) {
  31. this.parsePublisher.publish(_node.default.applicationId + 'clearCache', JSON.stringify({
  32. userId: user.id
  33. }));
  34. }
  35. // Request is the request object from cloud code functions. request.object is a ParseObject.
  36. _onCloudCodeMessage(type, request) {
  37. _logger.default.verbose('Raw request from cloud code current : %j | original : %j', request.object, request.original);
  38. // We need the full JSON which includes className
  39. const message = {
  40. currentParseObject: request.object._toFullJSON()
  41. };
  42. if (request.original) {
  43. message.originalParseObject = request.original._toFullJSON();
  44. }
  45. if (request.classLevelPermissions) {
  46. message.classLevelPermissions = request.classLevelPermissions;
  47. }
  48. this.parsePublisher.publish(type, JSON.stringify(message));
  49. }
  50. }
  51. exports.ParseCloudCodePublisher = ParseCloudCodePublisher;
  52. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJf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