Skip to content

Maintenance: update middleware signature to object #4480

@dreamorosi

Description

@dreamorosi

Summary

Currently the Middleware type for middleware functions describes a function with three parameters: params, options, next.

Since the function uses positional arguments, if I only want to use some of them I need to alias them to various combinations of _ (underscore) or linters might complain that the parameter is unused.

This is particularly apparent in middleware functions like the one below (from our docs) that only need to use next, which appears as last argument:

const loggingMiddleware: Middleware = async (_, __, next) => {
  logger.info('Request processed');
  await next();
};

I wonder if we can change the signature to instead have an object, so that customers can pick only the parameters they want from it, like:

const loggingMiddleware: Middleware = async ({ next }) => {
  logger.info('Request processed');
  await next();
};

Will this cause the same issues described in the destructuring pitfalls section of the docs?

Why is this needed?

So that middleware functions have less boilerplate in the signature in most cases.

Which area does this relate to?

Event Handler

Solution

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityinternalPRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)researchingThis item is currently under consideration and we'll update once we have more info

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions