function wrapMiddleware(shim, middleware, _name, route) {
  if (shim.isWrapped(middleware)) {
    return middleware
  }
  const spec = new MiddlewareSpec({
    matchArity: true,
    route,
    req: shim.FIRST,
    next: shim.LAST
  })

  const wrappedMw = shim.recordMiddleware(middleware, spec)
  if (shim.isAsyncFunction(middleware)) {
    return async function asyncShim() {
      return wrappedMw.apply(this, arguments)
    }
  }
  return wrappedMw
}
Wraps the middleware handler. In case of `pre` and `use`
route is not defined.

@param {object} shim instance of shim
@param {function} middleware function to record
@param {string} _name name of middleware
@param {object|null} route name of route
@returns {function} wrapped middleware function