1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.Subscription = void 0;
- var _logger = _interopRequireDefault(require("../logger"));
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- class Subscription {
- // It is query condition eg query.where
- constructor(className, query, queryHash) {
- this.className = className;
- this.query = query;
- this.hash = queryHash;
- this.clientRequestIds = new Map();
- }
- addClientSubscription(clientId, requestId) {
- if (!this.clientRequestIds.has(clientId)) {
- this.clientRequestIds.set(clientId, []);
- }
- const requestIds = this.clientRequestIds.get(clientId);
- requestIds.push(requestId);
- }
- deleteClientSubscription(clientId, requestId) {
- const requestIds = this.clientRequestIds.get(clientId);
- if (typeof requestIds === 'undefined') {
- _logger.default.error('Can not find client %d to delete', clientId);
- return;
- }
- const index = requestIds.indexOf(requestId);
- if (index < 0) {
- _logger.default.error('Can not find client %d subscription %d to delete', clientId, requestId);
- return;
- }
- requestIds.splice(index, 1);
- // Delete client reference if it has no subscription
- if (requestIds.length == 0) {
- this.clientRequestIds.delete(clientId);
- }
- }
- hasSubscribingClient() {
- return this.clientRequestIds.size > 0;
- }
- }
- exports.Subscription = Subscription;
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfbG9nZ2VyIiwiX2ludGVyb3BSZXF1aXJlRGVmYXVsdCIsInJlcXVpcmUiLCJlIiwiX19lc01vZHVsZSIsImRlZmF1bHQiLCJTdWJzY3JpcHRpb24iLCJjb25zdHJ1Y3RvciIsImNsYXNzTmFtZSIsInF1ZXJ5IiwicXVlcnlIYXNoIiwiaGFzaCIsImNsaWVudFJlcXVlc3RJZHMiLCJNYXAiLCJhZGRDbGllbnRTdWJzY3JpcHRpb24iLCJjbGllbnRJZCIsInJlcXVlc3RJZCIsImhhcyIsInNldCIsInJlcXVlc3RJZHMiLCJnZXQiLCJwdXNoIiwiZGVsZXRlQ2xpZW50U3Vic2NyaX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