* Refactor logging to provide common logger from LoggerAdapter Move logger logic de WinstonLoggerAdapter Further improvements in configuration Use logger instead of getLogger - Removes PLog module Reverts name changes nits * Adds additional logging levels as requirements * Adds tests for logging configuration * removes flaky test * investigate... * further investigation * Adds silent option to disable console output * Restores logs with VERBOSE in tests * Expose controller instead of adapter, reduces method requirements for adapter * Shuffles initializations around * Fix doc * Load cloudCode last to make sure the logger is available * Adds test to make sure we can load an adapter from npm module * extract defaults * Adds defaultMongoURI to defaults * fix defaults values * Proper error for PG failures * Disable flaky test
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import {matchesQuery, queryHash} from './QueryTools';
|
|
import logger from '../logger';
|
|
|
|
export type FlattenedObjectData = { [attr: string]: any };
|
|
export type QueryData = { [attr: string]: any };
|
|
|
|
class Subscription {
|
|
// It is query condition eg query.where
|
|
query: QueryData;
|
|
className: string;
|
|
hash: string;
|
|
clientRequestIds: Object;
|
|
|
|
constructor(className: string, query: QueryData, queryHash: string) {
|
|
this.className = className;
|
|
this.query = query;
|
|
this.hash = queryHash;
|
|
this.clientRequestIds = new Map();
|
|
}
|
|
|
|
addClientSubscription(clientId: number, requestId: number): void {
|
|
if (!this.clientRequestIds.has(clientId)) {
|
|
this.clientRequestIds.set(clientId, []);
|
|
}
|
|
let requestIds = this.clientRequestIds.get(clientId);
|
|
requestIds.push(requestId);
|
|
}
|
|
|
|
deleteClientSubscription(clientId: number, requestId: number): void {
|
|
let requestIds = this.clientRequestIds.get(clientId);
|
|
if (typeof requestIds === 'undefined') {
|
|
logger.error('Can not find client %d to delete', clientId);
|
|
return;
|
|
}
|
|
|
|
let index = requestIds.indexOf(requestId);
|
|
if (index < 0) {
|
|
logger.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(): boolean {
|
|
return this.clientRequestIds.size > 0;
|
|
}
|
|
}
|
|
|
|
export {
|
|
Subscription
|
|
}
|