From e35fc3b61a84a80a01af2123b4f08cb29504d0e3 Mon Sep 17 00:00:00 2001 From: Vicary A Date: Tue, 8 Oct 2024 17:13:18 +0800 Subject: [PATCH] fix: stubbed type FreshContext --- deno.json | 2 +- server.ts | 48 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/deno.json b/deno.json index e9ab878..fb675aa 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@vicary/fresh-graphql", - "version": "0.2.10", + "version": "0.2.11", "exports": "./mod.ts", "license": "MIT", "publish": { diff --git a/server.ts b/server.ts index f98b2a7..2e9b839 100644 --- a/server.ts +++ b/server.ts @@ -9,16 +9,54 @@ export type CreateHandlerOptions = { /** * A stubbed version of FreshContext. * - * Fresh 1.x uses HTTP import which is not compatible with JSR modules, to be - * updated when Fresh 2.x is released. + * Fresh 1.x uses HTTP import which is not compatible with JSR modules, this + * will be a direct export from Fresh when 2.x is out. * * ```ts * import type { FreshContext } from "jsr:@fresh/core@^2.0"; * ``` */ -export type FreshContext = { - request: Request; -}; +export interface FreshContext< + State = Record, + // deno-lint-ignore no-explicit-any + Data = any, + NotFoundData = Data, +> { + /** @types deprecated */ + localAddr?: Deno.NetAddr; + remoteAddr: Deno.NetAddr; + url: URL; + basePath: string; + route: string; + /** @deprecated Use `.route` instead */ + pattern: string; + destination: "internal" | "static" | "route" | "notFound"; + params: Record; + isPartial: boolean; + state: State; + config: { + dev: boolean; + build: { + outDir: string; + target: string | string[]; + }; + staticDir: string; + server: Partial; + basePath: string; + }; + data: Data; + /** The error that caused the error page to be loaded. */ + error?: unknown; + /** Sringified code frame of the error rendering failed (only in development mode) */ + codeFrame?: unknown; + + // These properties may be different + renderNotFound: (data?: NotFoundData) => Response | Promise; + render: ( + data?: Data, + ) => Response | Promise; + next: () => Promise; +} export function createHandler( manifest: TManifest,