<commit_before>const assert = require('assert');
const EventEmitter = require('events');
const TypeCheck = require('js-typecheck');
const minimatch = require('minimatch');
const Session = require('./Session');
const Action = require('./Action');
const Metadata = require('./Metadata');
const Reader = require('./Reader');
const Writer = require('./Writer');
const Utils = require('./Utils');

// symbols used for private instance variables to avoid any potential clashing
// caused by re-implementations
const _session = Symbol('session');
const _metadata = Symbol('metadata');


/**
 * A handler is used to bridge an execution method to Mebo.
 *
 * The data used to perform the execution of action through a handler
 * ({@link Handler.runAction}) is parsed using a reader {@link Reader}.
 *
 * The result of a handler is done through a {@link Writer}. Writers are designed
 * to support reporting a success output and an error output as well. The way the
 * result is serialized is determined by the writer implementation
 * ({@link Writer._successOutput}, {@link Writer._errorOutput}). All writers
 * shipped with Mebo have support for streams where in case of any readable stream
 * or buffer value they are piped to the output, otherwise the result is encoded
 * using JSON.
 *
 * Both reader and writer can be customized through options that can be either
 * defined through the action's metadata or directly through the handler. If you would
 * like to know more about the available options check out the respective
 * {@link Reader} & {@link Writer} documentation for the handler implementation
 * you are interested.
 *
 * Defining options through actions (detailed information can be found at
 * {@link Metadata}):
 * ```
 * @Mebo.register('myAction')
 * class MyAction extends Mebo.Action{
 *    constructor(){
 *      super();
 *
 *      // change 'name' for the registration name of the handler you
 *      // want to define the read & write options
 *      this.setMeta('handler.name', {
 *        readOptions: {
 *          someReadOption: true,
 *        },
 *        writeOptions: {
 *          someWriteOption: 10,
 *        },
 *      });
 *    }
 * }
 * ```
 *
 * Defining options directly through the handler:<commit_msg>improved documentation about the handler<commit_after>const assert = require('assert');
const EventEmitter = require('events');
const TypeCheck = require('js-typecheck');
const minimatch = require('minimatch');
const Session = require('./Session');
const Action = require('./Action');
const Metadata = require('./Metadata');
const Reader = require('./Reader');
const Writer = require('./Writer');
const Utils = require('./Utils');

// symbols used for private instance variables to avoid any potential clashing
// caused by re-implementations
const _session = Symbol('session');
const _metadata = Symbol('metadata');


/**
 * A handler is used to bridge an execution method to Mebo.
 *
 * The data used to perform the execution of action through a handler
 * ({@link Handler.runAction}) is parsed using a reader {@link Reader}.
 *
 * The result of a handler is done through a {@link Writer}. Writers are designed
 * to support reporting a success output and an error output as well. The way the
 * result is serialized is determined by the writer implementation
 * ({@link Writer._successOutput}, {@link Writer._errorOutput}). All writers
 * shipped with Mebo have support for streams where in case of any readable stream
 * or buffer value they are piped to the output, otherwise the result is encoded
 * using JSON.
 *
 * Both reader and writer can be customized through options that can be either
 * defined through the action's metadata or directly through the handler. If you would
 * like to know more about the available options check out the respective
 * {@link Reader} & {@link Writer} documentation for the handler implementation
 * you are interested.
 *
 * Defining options through actions (detailed information can be found at
 * {@link Metadata}):
 * ```
 * @Mebo.register('myAction')
 * class MyAction extends Mebo.Action{
 *    constructor(){
 *      super();
 *
 *      // change 'name' for the registration name of the handler you
 *      // want to define the read options
 *      this.setMeta('handler.name.readOptions', {
 *        someReadOption: true
 *      });
 *    }
 *
 *    async _perform(data){
 *      // ...
 *    }
 *
 *    _finalize(err, value){
 *
 *      // change 'name' for the registration name of the handler you
 *      // want to define the write options
 *      if (!err){
 *        // defining the write option inside of the _finalize to keep _perform as
 *        // abstract as possible. Since, _finalize is always called (even during
 *        // an error) after the execution of the action, it provides a way to
 *        // hook and define custom metadata related with the result.
 *        this.setMeta('handler.name.writeOptions', {
 *            someWriteOption: 10,
 *        });
 *      }
 *
 *      super._finalize(err, value);
 *    }
 * }
 * ```
 *
 * Defining options directly through the handler:
{'fraction_non_alphanumeric': 0.10476751030017657, 'fraction_numerical': 0.0007847753580537571, 'mean_word_length': 3.3910422049956934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1493883', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1256, 'n_words': 579}