<commit_before>const XMLDownloader = require("./xmldownloader");
const XMLParser = require("./xmlparser");
const EntryParser = require("./entryparser");

const EventEmitter = require("events");

// 3rd party dependencies
const CronJob = require("cron").CronJob;

class Realworks extends EventEmitter {
	constructor(options) {
		super();

		this._options = options;

		if(!this._options.user) throw new TypeError("'options.user' is not set");
		if(!this._options.password) throw new TypeError("'options.password' is not set");

		this._cron = this._options.cron || true;
		this._cronPattern = this._options.cronPattern || "0 0 9 * * *";
		this._cronTimezone = this._options.cronTimezone || "Europe/Amsterdam";

		if(!this._options.types) throw new TypeError("'options.types' is not set");
		if(typeof this._options.types == "string") this._options.types = [this._options.types];
		this._types = this._options.types;

		this._downloader = new XMLDownloader(this._options, this);
		this._converter = new XMLParser(this._options, this);
		this._parser = new EntryParser(this._options, this);

		if(this._cron) {
			try {
				this._cronjob = new CronJob(this._cronPattern, this.update, null, true, this._cronTimezone);
			} catch(err) {
				throw new Error("Invalid cron pattern: "+err.message);
			}
		}
	}

	update() {
		return new Promise((resolve, reject) => {
			Promise.all(this._types.map((type) => {
				return this._downloader.download(type)
					.then((xmlData) => {
						return this._converter.parse(xmlData);
					})
					.then((entries) => {
						return this._parser.parse(entries);
					});
			}))
			.then((results) => {
				resolve(results);
			})
			.catch((err) => {
				reject(err);
			});
		});
	}
}

module.exports = Realworks;<commit_msg>Emit error event on err in update<commit_after>const XMLDownloader = require("./xmldownloader");
const XMLParser = require("./xmlparser");
const EntryParser = require("./entryparser");

const EventEmitter = require("events");

// 3rd party dependencies
const CronJob = require("cron").CronJob;

class Realworks extends EventEmitter {
	constructor(options) {
		super();

		this._options = options;

		if(!this._options.user) throw new TypeError("'options.user' is not set");
		if(!this._options.password) throw new TypeError("'options.password' is not set");

		this._cron = this._options.cron || true;
		this._cronPattern = this._options.cronPattern || "0 0 9 * * *";
		this._cronTimezone = this._options.cronTimezone || "Europe/Amsterdam";

		if(!this._options.types) throw new TypeError("'options.types' is not set");
		if(typeof this._options.types == "string") this._options.types = [this._options.types];
		this._types = this._options.types;

		this._downloader = new XMLDownloader(this._options, this);
		this._converter = new XMLParser(this._options, this);
		this._parser = new EntryParser(this._options, this);

		if(this._cron) {
			try {
				this._cronjob = new CronJob(this._cronPattern, this.update, null, true, this._cronTimezone);
			} catch(err) {
				throw new Error("Invalid cron pattern: "+err.message);
			}
		}
	}

	update() {
		return new Promise((resolve, reject) => {
			Promise.all(this._types.map((type) => {
				return this._downloader.download(type)
					.then((xmlData) => {
						return this._converter.parse(xmlData);
					})
					.then((entries) => {
						return this._parser.parse(entries);
					});
			}))
			.then((results) => {
				resolve(results);
			})
			.catch((err) => {
				this.emit("error", err);
				reject(err);
			});
		});
	}
}

module.exports = Realworks;
{'fraction_non_alphanumeric': 0.1608195341004771, 'fraction_numerical': 0.002245298905416784, 'mean_word_length': 3.882191780821918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5722979', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1136, 'n_words': 233}