Files
cal.diy/packages/trpc/server/trpc.ts
T
+27 10ffd9bacd feat: Org user table - bulk actions (#10504)
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Leo Giovanetti <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>
Co-authored-by: cherish2003 <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: rkreddy99 <[email protected]>
Co-authored-by: varun thummar <Varun>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: Pradumn Kumar <[email protected]>
Co-authored-by: Richard Poelderl <[email protected]>
Co-authored-by: mohammed hussam <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: nicktrn <[email protected]>
Co-authored-by: sydwardrae <[email protected]>
Co-authored-by: Janakiram Yellapu <[email protected]>
Co-authored-by: GitStart-Cal.com <[email protected]>
Co-authored-by: sajanlamsal <[email protected]>
Co-authored-by: Cherish <[email protected]>
Co-authored-by: Danila <[email protected]>
Co-authored-by: Neel Patel <[email protected]>
Co-authored-by: Rama Krishna Reddy <[email protected]>
Co-authored-by: Varun Thummar <[email protected]>
Co-authored-by: Bhargav <[email protected]>
Co-authored-by: Pratik Kumar <[email protected]>
Co-authored-by: Ritesh Patil <[email protected]>
2023-08-15 14:07:38 -07:00

56 lines
1.7 KiB
TypeScript

import superjson from "superjson";
import { initTRPC } from "@trpc/server";
import type { createContextInner } from "./createContext";
import type { UserFromSession } from "./middlewares/sessionMiddleware";
export const tRPCContext = initTRPC.context<typeof createContextInner>().create({
transformer: superjson,
});
export const router = tRPCContext.router;
export const mergeRouters = tRPCContext.mergeRouters;
export const middleware = tRPCContext.middleware;
export const procedure = tRPCContext.procedure;
export type TrpcSessionUser = UserFromSession;
// eslint-disable-next-line @typescript-eslint/ban-types
const UNSTABLE_HANDLER_CACHE: Record<string, Function> = {};
/**
* This function will import the module defined in importer just once and then cache the default export of that module.
*
* It gives you the default export of the module.
*
* **Note: It is your job to ensure that the name provided is unique across all routes.**
* @example
* ```ts
const handler = await importHandler("myUniqueNameSpace", () => import("./getUser.handler"));
return handler({ ctx, input });
* ```
*/
export const importHandler = async <
T extends {
// eslint-disable-next-line @typescript-eslint/ban-types
default: Function;
}
>(
/**
* The name of the handler in cache. It has to be unique across all routes
*/
name: string,
importer: () => Promise<T>
) => {
const nameInCache = name as keyof typeof UNSTABLE_HANDLER_CACHE;
if (!UNSTABLE_HANDLER_CACHE[nameInCache]) {
const importedModule = await importer();
UNSTABLE_HANDLER_CACHE[nameInCache] = importedModule.default;
return importedModule.default as T["default"];
}
return UNSTABLE_HANDLER_CACHE[nameInCache] as unknown as T["default"];
};