<commit_before>const XevPubSub = require('./XevPubSub');
const redis = require('redis');
const { EventEmitter } = require('events');

class EventIdUtil {
	/**
	 * @param {string} serviceId
	 * @param {string} eventType
	 * @param {string[]} params
	*/
	static buildEventId(serviceId, eventType, params) {
		return `${serviceId}:${eventType}:${params.join(':')}`;
	}
	/** @param {string} eventId */
	static parseEventId(eventId) {
		const elements = eventId.split(':');
		if (elements.length < 2) {
			throw new Error(`invalid eventId: ${eventId}`);
		}
		const appendedParams = [];
		if (elements.length >= 3) {
			appendedParams.push(...elements.slice(2));
		}
		return {
			serviceId: elements[0],
			eventType: elements[1],
			appendedParams: appendedParams
		};
	}
}

class StreamEventIdUtil {
	/**
	 * @param {string} streamType
	 * @param {string} publisherId
	*/
	static buildStreamEventId(streamType, publisherId) {
		return EventIdUtil.buildEventId('frost-api', 'stream', [streamType, publisherId]);
	}
	/** @param {string} eventId */
	static parseStreamEventId(eventId) {
		const elements = EventIdUtil.parseEventId(eventId);
		if (elements.serviceId != 'frost-api') {
			throw new Error('serviceId is not frost-api');
		}
		if (elements.eventType != 'stream') {
			throw new Error('eventType is not stream');
		}
		if (elements.appendedParams.length != 2) {
			throw new Error('length of appendedParams is invalid');
		}
		return {
			serviceId: elements.appendedParams[0],
			eventType: elements.appendedParams[1]
		};
	}
}

class XevStream {
	/** @param {redis.RedisClient} redisClient */
	constructor() {
		this.sources = [];
		this.emitter = new EventEmitter();
		this.xev = new XevPubSub('frost-api');
		this.xev.on('message', (channel, message) => {
			// 自身のリスナーに対して投げる
			this.emitter.emit('data', (message instanceof String) ? message : JSON.parse(message));
			// 設定した別のStreamに投げる
			if (this.outgoingStreamId != null) {
				this.xev.publish(this.outgoingStreamId, message);
			}
		});
	}<commit_msg>revert eventId<commit_after>const XevPubSub = require('./XevPubSub');
const redis = require('redis');
const { EventEmitter } = require('events');

class EventIdUtil {
	/**
	 * @param {string} eventType
	 * @param {string[]} params
	*/
	static buildEventId(eventType, params) {
		return `${eventType}:${params.join(':')}`;
	}
	/** @param {string} eventId */
	static parseEventId(eventId) {
		const elements = eventId.split(':');
		const appendedParams = [];
		if (elements.length >= 2) {
			appendedParams.push(...elements.slice(1));
		}
		return {
			eventType: elements[0],
			appendedParams: appendedParams
		};
	}
}

class StreamEventIdUtil {
	/**
	 * @param {string} streamType
	 * @param {string} publisherId
	*/
	static buildStreamEventId(streamType, publisherId) {
		return EventIdUtil.buildEventId('stream', [streamType, publisherId]);
	}
	/** @param {string} eventId */
	static parseStreamEventId(eventId) {
		const elements = EventIdUtil.parseEventId(eventId);
		if (elements.eventType != 'stream') {
			throw new Error('eventType is not stream');
		}
		if (elements.appendedParams.length != 2) {
			throw new Error('length of appendedParams is invalid');
		}
		return {
			streamType: elements.appendedParams[0],
			publisherId: elements.appendedParams[1]
		};
	}
}

class XevStream {
	/** @param {redis.RedisClient} redisClient */
	constructor() {
		this.sources = [];
		this.emitter = new EventEmitter();
		this.xev = new XevPubSub('frost-api');
		this.xev.on('message', (channel, message) => {
			// 自身のリスナーに対して投げる
			this.emitter.emit('data', (message instanceof String) ? message : JSON.parse(message));
			// 設定した別のStreamに投げる
			if (this.outgoingStreamId != null) {
				this.xev.publish(this.outgoingStreamId, message);
			}
		});
	}
{'fraction_non_alphanumeric': 0.16016971625563511, 'fraction_numerical': 0.0037125430920180325, 'mean_word_length': 4.2027586206896554, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '1838415', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1287, 'n_words': 259}