<commit_before>/* jshint -W097 */
/* globals require, module */
'use strict';

const q = require('q'),
    EventEmitter = require('events'),
    util = require('util'),
    Firebase = require('firebase'),
    FirebaseEventType = require('../lookups/firebaseeventtype.js'),
    FirebaseEvent = require('../lookups/firebaseevent.js'),
    FirebaseUtility = require('../firebase/firebaseutility.js'),
    ValueMessage = require('../types/messages/value.js');

const DATA_CHANGED = 'data-changed';

/**
 * Handles all subscription requests to watch for data changes
 * @param {Firebase} firebase the root node
 * @constructor
 */
function SubscriptionService(firebase) {
    EventEmitter.call(this);

    //var activeSubscriptions = {};

    /**
     * Subscribe to a node
     * @param {RequestPacket} requestPacket the subscription packet
     * @returns {Promise} resolves once the subscription is active
     */
    this.subscribe = function(requestPacket) {

        var message = requestPacket.message;
        var target = FirebaseUtility.getDataChild(firebase, message.path);

        var firebaseEvent;
        switch(message.eventType) {
            case FirebaseEventType.CHANGED:
                firebaseEvent = 'value';
                break;
            default:
                throw new Error('Invalid Firebase event type.');
        }

        target.on(firebaseEvent, function(snapshot) {
            var valueMessage = new ValueMessage(message.requestID, snapshot.val());
            requestPacket.reply(valueMessage).send();
        });

        return q();
    };

    /**
     * Subscribe a user to a channel
     * @param {RequestPacket} requestPacket the request
     * @returns {Promise} resolves once the subscription is active
     */
    this.subscribeChannel = function(requestPacket) {

        var message = requestPacket.message;
        var target = FirebaseUtility.getChannelRoot(firebase)
            .child(message.path);

        return FirebaseUtility.getFirebaseServerTime(firebase)
            .then(function success(serverTime) {

                // Subscribe to the event
                target.on(FirebaseEvent.t CHILD_ADDED, function(snapshot) {

                    var eventData = snapshot.val();
                    if (eventData.dateAdded >= serverTime) {<commit_msg>Fixed typo<commit_after>/* jshint -W097 */
/* globals require, module */
'use strict';

const q = require('q'),
    EventEmitter = require('events'),
    util = require('util'),
    Firebase = require('firebase'),
    FirebaseEventType = require('../lookups/firebaseeventtype.js'),
    FirebaseEvent = require('../lookups/firebaseevent.js'),
    FirebaseUtility = require('../firebase/firebaseutility.js'),
    ValueMessage = require('../types/messages/value.js');

const DATA_CHANGED = 'data-changed';

/**
 * Handles all subscription requests to watch for data changes
 * @param {Firebase} firebase the root node
 * @constructor
 */
function SubscriptionService(firebase) {
    EventEmitter.call(this);

    //var activeSubscriptions = {};

    /**
     * Subscribe to a node
     * @param {RequestPacket} requestPacket the subscription packet
     * @returns {Promise} resolves once the subscription is active
     */
    this.subscribe = function(requestPacket) {

        var message = requestPacket.message;
        var target = FirebaseUtility.getDataChild(firebase, message.path);

        var firebaseEvent;
        switch(message.eventType) {
            case FirebaseEventType.CHANGED:
                firebaseEvent = 'value';
                break;
            default:
                throw new Error('Invalid Firebase event type.');
        }

        target.on(firebaseEvent, function(snapshot) {
            var valueMessage = new ValueMessage(message.requestID, snapshot.val());
            requestPacket.reply(valueMessage).send();
        });

        return q();
    };

    /**
     * Subscribe a user to a channel
     * @param {RequestPacket} requestPacket the request
     * @returns {Promise} resolves once the subscription is active
     */
    this.subscribeChannel = function(requestPacket) {

        var message = requestPacket.message;
        var target = FirebaseUtility.getChannelRoot(firebase)
            .child(message.path);

        return FirebaseUtility.getFirebaseServerTime(firebase)
            .then(function success(serverTime) {

                // Subscribe to the event
                target.on(FirebaseEvent.CHILD_ADDED, function(snapshot) {

                    var eventData = snapshot.val();
                    if (eventData.dateAdded >= serverTime) {
{'fraction_non_alphanumeric': 0.10959497509205111, 'fraction_numerical': 0.001299545159194282, 'mean_word_length': 2.5441289332310055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2745995', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1201, 'n_words': 292}