Massage types

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

View File

@@ -1,40 +1,57 @@
// types.ts // types.ts
// 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([
export type Method = "get" | "post" | "put" | "patch" | "delete"; z.literal("get"),
z.literal("post"),
z.literal("put"),
export type DenoRequest = globalThis.Request; z.literal("patch"),
export type UserRequest = {}; z.literal("delete"),
export type Request = { ]);
pattern: string;
path: string; export type Method = z.infer<typeof methodParser>;
method: Method;
parameters: object; const massageMethod = (input: string): Method => {
denoRequest: globalThis.Request; const r = methodParser.parse(input.toLowerCase())
};
export type ProcessedRoute = { pattern: URLPattern; method: Method; handler: Handler }; return r;
};
export type DenoRequest = globalThis.Request;
export type Response = { export type DenoResponse=globalThis.Response;
code: HttpCode; export type UserRequest = {};
contentType: ContentType; export type Request = {
result: string; pattern: string;
}; path: string;
method: Method;
export type Handler = (req: Request) => Promise<Response>; parameters: object;
denoRequest: globalThis.Request;
export type Route = { };
path: string; export type ProcessedRoute = {
methods: Method[]; pattern: URLPattern;
handler: Handler; method: Method;
interruptable?: boolean handler: Handler;
}; };
export type Response = {
code: HttpCode;
contentType: ContentType;
result: string;
};
export type Handler = (req: Request) => Promise<Response>;
export type Route = {
path: string;
methods: Method[];
handler: Handler;
interruptable?: boolean;
};
export { massageMethod };