import { ComponentChildren } from "preact"; import { AsyncLayout, AsyncRoute, LayoutContext, RouteContext, StartOptions, } from "./types.ts"; import { checkAsyncComponent } from "./render.ts"; import { AppContext } from "$fresh/server.ts"; export function defineConfig(config: StartOptions): StartOptions { return config; } // Route creation helpers export function defineRoute< T, >( fn: ( req: Request, ctx: RouteContext, ) => ComponentChildren | Response | Promise, ): AsyncRoute { // deno-lint-ignore no-explicit-any if (checkAsyncComponent(fn)) return fn as any; // deno-lint-ignore require-await return async (req, ctx) => fn(req, ctx); } // Layout creation helper export function defineLayout( fn: ( req: Request, ctx: LayoutContext, ) => ComponentChildren | Response | Promise, ): AsyncLayout { // deno-lint-ignore no-explicit-any if (checkAsyncComponent(fn)) return fn as any; // deno-lint-ignore require-await return async (req, ctx) => fn(req, ctx); } // App creation helper export function defineApp( fn: ( req: Request, ctx: AppContext, ) => ComponentChildren | Response | Promise, ): AsyncLayout { // deno-lint-ignore no-explicit-any if (checkAsyncComponent(fn)) return fn as any; // deno-lint-ignore require-await return async (req, ctx) => fn(req, ctx); }