function paramConverterMiddleware(handler, action) {

	function convertProperties(obj, schema) {
		Object.keys(schema).forEach(key => {
			const s = schema[key];
			const val = obj[key];
			if (val == null)
				return;

			if (s.type == "string" && typeof val !== "string") {
				obj[key] = "" + val;
			} else if (s.type == "number" && typeof val !== "number") {
				obj[key] = Number(val);
			} else if (s.type == "boolean" && typeof val !== "boolean") {
				obj[key] = String(val).toLowerCase() === "true";
			} else if (s.type == "date" && !(val instanceof Date)) {
				obj[key] = new Date(val);
			} else if (s.type == "object")
				convertProperties(val, s.props);
		});
	}

	// Wrap a param validator
	if (action.params && typeof action.params === "object") {
		return function convertContextParams(ctx) {
			convertProperties(ctx.params, action.params);

			return handler(ctx);
		};
	}
	return handler;
}
function paramConverterMiddleware(handler, action) {

	function convertProperties(obj, schema) {
		Object.keys(schema).forEach(key => {
			const s = schema[key];
			const val = obj[key];
			if (val == null)
				return;

			if (s.type == "string" && typeof val !== "string") {
				obj[key] = "" + val;
			} else if (s.type == "number" && typeof val !== "number") {
				obj[key] = Number(val);
			} else if (s.type == "boolean" && typeof val !== "boolean") {
				obj[key] = String(val).toLowerCase() === "true";
			} else if (s.type == "date" && !(val instanceof Date)) {
				obj[key] = new Date(val);
			} else if (s.type == "object")
				convertProperties(val, s.props);
		});
	}

	// Wrap a param validator
	if (action.params && typeof action.params === "object") {
		return function convertContextParams(ctx) {
			convertProperties(ctx.params, action.params);

			return handler(ctx);
		};
	}
	return handler;
}
function paramConverterMiddleware ( handler , action ) { function convertProperties ( obj , schema ) { Object . keys ( schema ) . forEach ( key => { const s = schema [ key ] ; const val = obj [ key ] ; if ( val == null ) return ; if ( s . type == "string" && typeof val !== "string" ) { obj [ key ] = "" + val ; } else if ( s . type == "number" && typeof val !== "number" ) { obj [ key ] = Number ( val ) ; } else if ( s . type == "boolean" && typeof val !== "boolean" ) { obj [ key ] = String ( val ) . toLowerCase ( ) === "true" ; } else if ( s . type == "date" && ! ( val instanceof Date ) ) { obj [ key ] = new Date ( val ) ; } else if ( s . type == "object" ) convertProperties ( val , s . props ) ; } ) ; } // Wrap a param validator if ( action . params && typeof action . params === "object" ) { return function convertContextParams ( ctx ) { convertProperties ( ctx . params , action . params ) ; return handler ( ctx ) ; } ; } return handler ; }
Proof-of-Concept middleware to convert context params
@param {Function} handler
@param {Action} action
Proof - of - Concept middleware to convert context params
Convert params from context to context params