// types.ts // FIXME: split this up into types used by app developers and types internal // to the framework. // FIXME: the use of types like Request and Response cause problems because it's // easy to forget to import them and then all sorts of random typechecking errors // start showing up even if the code is sound. So find other names for them. import { z } from "zod"; import { HttpCode, httpCodes } from "./http-codes.ts"; import { ContentType, contentTypes } from "./content-types.ts"; const methodParser = z.union([ z.literal("GET"), z.literal("POST"), z.literal("PUT"), z.literal("PATCH"), z.literal("DELETE"), ]); export type Method = z.infer; const massageMethod = (input: string): Method => { const r = methodParser.parse(input.toUpperCase()); return r; }; export type DenoRequest = globalThis.Request; export type DenoResponse = globalThis.Response; export type UserRequest = {}; export type Request = { pattern: string; path: string; method: Method; parameters: object; denoRequest: globalThis.Request; }; export type InternalHandler = (req: DenoRequest) => Promise; export type Handler = (req: Request) => Promise | Response; export type ProcessedRoute = { pattern: URLPattern; method: Method; handler: InternalHandler; }; export type Response = { code: HttpCode; contentType: ContentType; result: string; }; export type Route = { path: string; methods: Method[]; handler: Handler; interruptable?: boolean; }; export { massageMethod };