<commit_before>// Business process dedicated search query handler
// (used to handle business processes table in official roles)

'use strict';

var isNaturalNumber   = require('es5-ext/number/is-natural')
  , findKey           = require('es5-ext/object/find-key')
  , appLocation       = require('mano/lib/client/location')
  , setupQueryHandler = require('../../../utils/setup-client-query-handler')

  , stringify = JSON.stringify;

module.exports = exports = function (listManager/*, pathname*/) {
	var queryHandler = setupQueryHandler(exports.conf, appLocation, arguments[2] || '/')
	  , statusMap = listManager._statusMap;
	queryHandler._statusMap = statusMap;
	queryHandler._statusMapDefaultKey = findKey(statusMap, function (data) { return data.default; });
	queryHandler._listManager = listManager;
	queryHandler.on('query', function (query) { listManager.update(query); });
};
exports.conf = [
	{
		name: 'status',
		ensure: function (value) {
			if (!value) return this._statusMapDefaultKey;
			if (!this._statusMap[value]) throw new Error("Unreconized status value " + stringify(value));
			return (value === 'all') ? null : value;
		}
	},
	{ name: 'search' },
	{
		name: 'page',
		ensure: function (value) {
			var num;
			if (value == null) return '1';
			if (isNaN(value)) throw new Error("Unrecognized page value " + stringify(value));
			num = Number(value);
			if (!isNaturalNumber(num)) throw new Error("Unreconized page value " + stringify(value));
			if (num <= 1) throw new Error("Unexpected page value " + stringify(value));
			if (num > this._listManager.pageCount) throw new Error("Page value overflow");
			return value;
		}
	}
];<commit_msg>Fix 'page' value validation<commit_after>// Business process dedicated search query handler
// (used to handle business processes table in official roles)

'use strict';

var isNaturalNumber   = require('es5-ext/number/is-natural')
  , findKey           = require('es5-ext/object/find-key')
  , appLocation       = require('mano/lib/client/location')
  , setupQueryHandler = require('../../../utils/setup-client-query-handler')

  , ceil = Math.ceil, stringify = JSON.stringify;

module.exports = exports = function (listManager/*, pathname*/) {
	var queryHandler = setupQueryHandler(exports.conf, appLocation, arguments[2] || '/')
	  , statusMap = listManager._statusMap;
	queryHandler._statusMap = statusMap;
	queryHandler._statusViews = listManager._statusViews;
	queryHandler._statusMapDefaultKey = findKey(statusMap, function (data) { return data.default; });
	queryHandler._listManager = listManager;
	queryHandler.on('query', function (query) { listManager.update(query); });
};
exports.conf = [
	{
		name: 'status',
		ensure: function (value) {
			if (!value) return this._statusMapDefaultKey;
			if (!this._statusMap[value]) throw new Error("Unreconized status value " + stringify(value));
			return (value === 'all') ? null : value;
		}
	},
	{ name: 'search' },
	{
		name: 'page',
		ensure: function (value, query) {
			var num, pageCount;
			if (value == null) return '1';
			if (isNaN(value)) throw new Error("Unrecognized page value " + stringify(value));
			num = Number(value);
			if (!isNaturalNumber(num)) throw new Error("Unreconized page value " + stringify(value));
			if (num <= 1) throw new Error("Unexpected page value " + stringify(value));
			pageCount = ceil(this._statusViews[query.status || 'all'].totalSize / 50);
			if (num > pageCount) throw new Error("Page value overflow");
			return value;
		}
	}
];
{'fraction_non_alphanumeric': 0.14881462439303056, 'fraction_numerical': 0.003427592116538132, 'mean_word_length': 4.306060606060606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5526755', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1049, 'n_words': 271}