.ts
TypeScript
(application/typescript)
import fastify from "fastify";

import type { AppThemeScheme, SectionsWithPages } from "../../app/types";

declare module "@ethicdevs/fastify-custom-session" {
  declare interface CustomSession extends AppSessionData {}
}

declare module "fastify" {
  interface FastifyInstance {
    // from prisma plugin
    prisma: PrismaClient;
  }
  interface FastifyRequest {
    // from prisma plugin
    prisma: PrismaClient;

    // from cookies
    cookies: {
      theme_scheme: AppThemeScheme;
    };

    // from app
    sectionsWithPages: SectionsWithPages;

    // from react-monolith
    // A request utility that maps a viewName to its routerPath
    namedViewsPathMap: Record<string, string>;
    // A request utility that maps a routerPath to its viewName
    pathNamedViewsMap: Record<string, string>;
  }

  interface FastifyReply {
    makeRequestHandler: (
      request: FastifyRequest,
      reply: FastifyReply
    ) => <T extends Record<string, any>>(
      viewName: string,
      props: T & CommonViewProps,
      viewCtx?: ViewContext
    ) => Promise<
      FastifyReply<
        Server,
        IncomingMessage,
        ServerResponse,
        RouteGenericInterface,
        unknown
      >
    >;
  }
}