William Nemenchainitial commit
86fb32e9/11/2022, 1:13:39 AM
.ts
TypeScript
(application/typescript)
import fastify from "fastify";

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

declare module "fastify" {
  interface FastifyRequest {
    cookies: {
      theme_scheme: AppThemeScheme;
    };
    sectionsWithPages: SectionsWithPages;
    // 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
      >
    >;
  }
}