Massage types

This commit is contained in:
Michael Wolf
2025-03-07 15:23:20 -06:00
parent ad2b85bc2b
commit d6fda3fdb3

View File

@@ -3,15 +3,28 @@
// FIXME: split this up into types used by app developers and types internal // FIXME: split this up into types used by app developers and types internal
// to the framework. // to the framework.
import { z } from "zod";
import { HttpCode, httpCodes } from "./http-codes.ts"; import { HttpCode, httpCodes } from "./http-codes.ts";
import { ContentType, contentTypes } from "./content-types"; 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 = "get" | "post" | "put" | "patch" | "delete"; export type Method = z.infer<typeof methodParser>;
const massageMethod = (input: string): Method => {
const r = methodParser.parse(input.toLowerCase())
return r;
};
export type DenoRequest = globalThis.Request; export type DenoRequest = globalThis.Request;
export type DenoResponse=globalThis.Response;
export type UserRequest = {}; export type UserRequest = {};
export type Request = { export type Request = {
pattern: string; pattern: string;
@@ -20,9 +33,11 @@ export type Request = {
parameters: object; parameters: object;
denoRequest: globalThis.Request; denoRequest: globalThis.Request;
}; };
export type ProcessedRoute = { pattern: URLPattern; method: Method; handler: Handler }; export type ProcessedRoute = {
pattern: URLPattern;
method: Method;
handler: Handler;
};
export type Response = { export type Response = {
code: HttpCode; code: HttpCode;
@@ -36,5 +51,7 @@ export type Route = {
path: string; path: string;
methods: Method[]; methods: Method[];
handler: Handler; handler: Handler;
interruptable?: boolean interruptable?: boolean;
}; };
export { massageMethod };