Subscription.js 5.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Subscription = void 0;
  6. var _logger = _interopRequireDefault(require("../logger"));
  7. function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
  8. class Subscription {
  9. // It is query condition eg query.where
  10. constructor(className, query, queryHash) {
  11. this.className = className;
  12. this.query = query;
  13. this.hash = queryHash;
  14. this.clientRequestIds = new Map();
  15. }
  16. addClientSubscription(clientId, requestId) {
  17. if (!this.clientRequestIds.has(clientId)) {
  18. this.clientRequestIds.set(clientId, []);
  19. }
  20. const requestIds = this.clientRequestIds.get(clientId);
  21. requestIds.push(requestId);
  22. }
  23. deleteClientSubscription(clientId, requestId) {
  24. const requestIds = this.clientRequestIds.get(clientId);
  25. if (typeof requestIds === 'undefined') {
  26. _logger.default.error('Can not find client %d to delete', clientId);
  27. return;
  28. }
  29. const index = requestIds.indexOf(requestId);
  30. if (index < 0) {
  31. _logger.default.error('Can not find client %d subscription %d to delete', clientId, requestId);
  32. return;
  33. }
  34. requestIds.splice(index, 1);
  35. // Delete client reference if it has no subscription
  36. if (requestIds.length == 0) {
  37. this.clientRequestIds.delete(clientId);
  38. }
  39. }
  40. hasSubscribingClient() {
  41. return this.clientRequestIds.size > 0;
  42. }
  43. }
  44. exports.Subscription = Subscription;
  45. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfbG9nZ2VyIiwiX2ludGVyb3BSZXF1aXJlRGVmYXVsdCIsInJlcXVpcmUiLCJlIiwiX19lc01vZHVsZSIsImRlZmF1bHQiLCJTdWJzY3JpcHRpb24iLCJjb25zdHJ1Y3RvciIsImNsYXNzTmFtZSIsInF1ZXJ5IiwicXVlcnlIYXNoIiwiaGFzaCIsImNsaWVudFJlcXVlc3RJZHMiLCJNYXAiLCJhZGRDbGllbnRTdWJzY3JpcHRpb24iLC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