feathers-hooks-common icon indicating copy to clipboard operation
feathers-hooks-common copied to clipboard

paramsForServer Hook

Open DaddyWarbucks opened this issue 3 years ago • 3 comments
trafficstars

I think we should update the docs to include an example of how one might use the paramsForServer as a hook.

const paramsForServerHook = (...whitelist) => (context) => {
  context.params = paramsForServer(context.params, ...whitelist);
  return context;
};

I am not a fan of having to use the paramsForServer on every service call and would rather have it work more generically via a client side hook.

I can update the docs at some point, but wanted to capture my solution.

DaddyWarbucks avatar Jun 02 '22 19:06 DaddyWarbucks

I would go a more drastic way. We should deprecate the current paramsForServer util and add a paramsForServerHook and advertise it as the new way to go.

In a next major release, I would like to rename the paramsForServer util to paramsForServerUtil. And in another major release I would like to rename paramsForServerHook to paramsForServer.

fratzinger avatar Feb 16 '23 15:02 fratzinger

Here is a question, what do the params hooks do differently than something like this?

async (context) => {
  const { myParam, ...query } = context.params.query || {}

  context.params = {
    ...query,
    myParam
  }
}

daffl avatar Feb 16 '23 16:02 daffl