/** * Prepares the route params by checking the existing params and meta data. * Meta data is prioritized over params. * Params are prioritized over predetermined id, action and resource. * This means, we can use `meta` for user supplied params (both manually or from the query string) */ export const prepareRouteParams = < TRouteParams extends Record = Record, >( routeParams: (keyof TRouteParams)[], meta: Record = {}, ): Partial => { return routeParams.reduce( (acc, key) => { const value = meta[key as string]; if (typeof value !== "undefined") { acc[key] = value as TRouteParams[keyof TRouteParams]; } return acc; }, {} as Partial, ); };