import { check } from 'meteor/check';
import { Mongo } from 'meteor/mongo'
import TransliterationDb from '../../collections/transliterationdb';
import { Counts } from 'meteor/tmeasday:publish-counts';

import { Logger } from 'meteor/ostrio:logger';
import { LoggerFile } from 'meteor/ostrio:loggerfile';

var log = new Logger();
(new LoggerFile(log)).enable();

Meteor.publish("transliterationdb", function({ limit }) {
    if (!this.userId) {
        return this.ready();
    }
    check(limit, Number);
    Meteor.settings.enableDebug ? log.debug(`transliterationdbPublisher => start publish transliterationdb `, limit, Meteor.user().username) : '';
    return TransliterationDb.find({}, {
        sort: { ID: 1 },
        limit: limit
    });
});

Meteor.publish("transliterationdbCount", function() {
    if (!this.userId) {
        return this.ready();
    }
    Meteor.settings.enableDebug ? log.debug(`transliterationdbCountPublisher => start publish transliterationdbCount `, {}, Meteor.user().username) : '';
    Counts.publish(this, 'transliterationCount', TransliterationDb.find({}), { fastCount: true });
});