<commit_before>var Structr = require('structr');


var Middleware = Structr({

	/**
	 */

	'__construct': function(controller)
	{
		this._middleware = [];

		this._controller = controller;

		//instantiated routers
		this._routers = {};

		//types of routers
		this.types = [];
	},

	/**
	 */

	'add': function(module)
	{
		this._middleware.push(module);

		this.types = module.types.concat(this.types);

		for(var i = module.types.length; i--;)
		{
			this._controller._createTypeMethod(module.types[i]);
		}
	},

	/**
	 */

	'router': function(expr)
	{
		for(var i = this._middleware.length; i--;)
		{
			//get the factory name. some middleware may return different routers depending on the expression metadata, such as pull -multi
			var mw = this._middleware[i], name = mw.test(expr);

			if(name) return this._router(mw, name);
		}

		return null;
	},

	/**
	 */

	'_router': function(tester, name)
	{
		return this._routers[ name ] || this._newRouter(tester, name);
	},

	/**
	 */

	'_newRouter': function(tester, name)
	{
		var router = tester.newRouter(name);

		router.type = name;
		router.controller = this._controller;

		this._routers[ name ] = router;

		return router;
	}
});


module.exports = function(controller)
{
	var mw = new Middleware(controller);

	//needs to be useable online = manual
	mw.add(require('./pushPull/push'));
	mw.add(require('./pushPull/pull'));

	return mw;
}<commit_msg>added default middleware (requires no prefix: pull/push)<commit_after>var Structr = require('structr');


var Middleware = Structr({

	/**
	 */

	'__construct': function(controller)
	{
		this._middleware = [];

		this._controller = controller;

		//instantiated routers
		this._routers = {};

		//types of routers
		this.types = [];
	},

	/**
	 */

	'add': function(module)
	{
		this._middleware.push(module);

		this.types = module.types.concat(this.types);

		for(var i = module.types.length; i--;)
		{
			this._controller._createTypeMethod(module.types[i]);
		}
	},

	/**
	 */

	'router': function(expr)
	{
		for(var i = this._middleware.length; i--;)
		{
			//get the factory name. some middleware may return different routers depending on the expression metadata, such as pull -multi
			var mw = this._middleware[i], name = mw.test(expr);

			if(name) return this._router(mw, name);
		}

		return null;
	},

	/**
	 */

	'_router': function(tester, name)
	{
		return this._routers[ name ] || this._newRouter(tester, name);
	},

	/**
	 */

	'_newRouter': function(tester, name)
	{
		var router = tester.newRouter(name);

		router.type = name;
		router.controller = this._controller;

		this._routers[ name ] = router;

		return router;
	}
});


module.exports = function(controller)
{
	var mw = new Middleware(controller);

	//needs to be useable online = manual
	mw.add(require('./pushPull/push'));
	mw.add(require('./pushPull/pull'));
	mw.add(require('./default'));

	return mw;
}
{'fraction_non_alphanumeric': 0.16574585635359115, 'fraction_numerical': 0.0, 'mean_word_length': 3.3303437967115097, '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': '2212455', 'n_tokens_mistral': 1107, 'n_tokens_neox': 970, 'n_words': 213}