refactor: share the PRECHECK type at the top level

This commit is contained in:
Andy Burke 2025-08-08 17:38:15 -07:00
parent 41c7802a36
commit 18b58ba94a
4 changed files with 9 additions and 9 deletions

View file

@ -6,7 +6,7 @@
import * as fs from '@std/fs';
import * as path from '@std/path';
import * as media_types from '@std/media-types';
import { SERVER } from '../server.ts';
import { PRECHECK, SERVER } from '../server.ts';
import { getCookies } from '@std/http/cookie';
let PUT_PATHS_ALLOWED: string[] | undefined = undefined;
@ -18,7 +18,6 @@ export type HANDLER_METHOD = (
normalized_path: string,
server: SERVER
) => Promise<Response | undefined> | Response | undefined;
export type PRECHECK = (request: Request, meta: Record<string, any>) => Promise<Response> | Response | undefined;
export const PRECHECKS: Partial<Record<HTTP_METHOD, PRECHECK[]>> = {};
export const HANDLERS: Partial<Record<HTTP_METHOD, HANDLER_METHOD>> = {
HEAD: async (_request: Request, normalized_path: string, _server: SERVER): Promise<Response | undefined> => {

View file

@ -8,12 +8,7 @@ import { walk } from '@std/fs';
import { delay } from '@std/async/delay';
import * as path from '@std/path';
import { getCookies } from '@std/http/cookie';
/** A `PRECHECK` must take a `Request` and `meta` data and return a `Response` IF THERE IS A PROBLEM. */
export type PRECHECK = (
request: Request,
meta: Record<string, any>
) => undefined | Response | Promise<undefined | Response>;
import { PRECHECK } from '@andyburke/serverus/server';
/** A `PRECHECK_TABLE` maps from HTTP methods to an array of `PRECHECK`s to be run. */
export type PRECHECKS_TABLE = Record<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', PRECHECK[]>;