export type PromisesMap<T extends Record<string, unknown>> = {
  [P in keyof T]: Promise<T[P]> | T[P];
};

export const promiseAllObject = <T extends Record<string, unknown>>(obj: PromisesMap<T>): Promise<T> => {
  const keys = Object.keys(obj) as (keyof T)[];
  const values = keys.map((key) => obj[key]);

  return Promise.all(values).then((values) => {
    return values.reduce((acc, value, index) => {
      acc[keys[index]] = value;
      return acc;
    }, {} as T);
  });
};
