import { initTRPC } from '@trpc/server';
import ExpiryMap from 'expiry-map';
import pMemoize from 'p-memoize';
import superjson from 'superjson';
import { oneMinuteInMs } from '../../../shared/utils.js';
export const trpcContext = ({ req }) => ({
    userId: req.cookies.c,
    userAgent: req.headers['user-agent'],
    user: 'user' in req ? req.user : null,
});
export const t = initTRPC.context().create({ transformer: superjson });
export const passInputTo = (fn) => ({ input }) => fn(input);
export const memoizeForUI = (fn) => {
    const cache = new ExpiryMap(5 * oneMinuteInMs);
    return pMemoize(fn, { cacheKey: x => JSON.stringify(x), cache });
};
