4 Commits

Author SHA1 Message Date
Michael Wolf
6d2779ba83 Fix import and avoid type defn nonsense 2025-03-07 15:23:47 -06:00
Michael Wolf
c19e6a9537 Refmt 2025-03-07 15:23:38 -06:00
Michael Wolf
d48a533d42 Fix import 2025-03-07 15:23:29 -06:00
Michael Wolf
d6fda3fdb3 Massage types 2025-03-07 15:23:20 -06:00
4 changed files with 80 additions and 63 deletions

View File

@@ -1,4 +1,4 @@
import { Extensible } from "./interfaces";
import { Extensible } from "./interfaces.ts";
export type HttpCode = {
code: number;
@@ -11,8 +11,10 @@ type CodeDefinitions = {
[K: string]: HttpCode;
};
};
// FIXME: Figure out how to brand CodeDefinitions in a way that isn't
// tedious.
const httpCodes: CodeDefinitions & Extensible = {
const httpCodes: CodeDefinitions = {
success: {
OK: { code: 200, name: "OK", "description": "" },
Created: { code: 201, name: "Created" },

View File

@@ -3,14 +3,20 @@
import { sleep } from "https://deno.land/x/sleep/mod.ts";
import { HttpCode, httpCodes } from "./http-codes.ts";
import { ContentType, contentTypes } from "./content-types";
import { services } from "./services";
import {DenoRequest, Handler, Response, Method, UserRequest, Request, Route, ProcessedRoute } from './types.ts'
import { ContentType, contentTypes } from "./content-types.ts";
import { services } from "./services.ts";
import {
DenoRequest,
Handler,
Method,
ProcessedRoute,
Request,
Response,
Route,
UserRequest,
} from "./types.ts";
const phandler: Handler = async (req: Request) => {
const phandler: Handler = async (_req: Request) => {
const code = httpCodes.success.OK;
return {
code,
@@ -19,8 +25,6 @@ const phandler: Handler = async (req: Request) => {
};
};
// FIXME: Obviously put this somewhere else
const okText = (out: string) => {
const code = httpCodes.success.OK;
@@ -37,9 +41,10 @@ const routes: Route[] = [
path: "/slow",
methods: ["get"],
handler: async (_req) => {
console.log("starting slow request") ;
console.log("starting slow request");
await sleep(10);
console.log("finishing slow request"); return okText("that was slow");
console.log("finishing slow request");
return okText("that was slow");
},
},
{
@@ -91,11 +96,4 @@ const routes: Route[] = [
},
];
export {routes}
export { routes };

View File

@@ -2,7 +2,7 @@
import { randomNumber } from "https://deno.land/x/random_number/mod.ts";
import { config } from "./config.ts";
import { getLogs, log } from "./logging";
import { getLogs, log } from "./logging.ts";
//const database = Client({

View File

@@ -3,15 +3,28 @@
// FIXME: split this up into types used by app developers and types internal
// to the framework.
import { z } from "zod";
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 DenoResponse=globalThis.Response;
export type UserRequest = {};
export type Request = {
pattern: string;
@@ -20,9 +33,11 @@ export type Request = {
parameters: object;
denoRequest: globalThis.Request;
};
export type ProcessedRoute = { pattern: URLPattern; method: Method; handler: Handler };
export type ProcessedRoute = {
pattern: URLPattern;
method: Method;
handler: Handler;
};
export type Response = {
code: HttpCode;
@@ -36,5 +51,7 @@ export type Route = {
path: string;
methods: Method[];
handler: Handler;
interruptable?: boolean
interruptable?: boolean;
};
export { massageMethod };