refactor: make PRECHECKs an array again

This commit is contained in:
Andy Burke 2025-06-25 15:30:55 -07:00
parent 5ee654f280
commit 62eba8612b
4 changed files with 30 additions and 21 deletions

View file

@ -56,7 +56,7 @@ export type PRECHECK = (
request: Request,
meta: Record<string, any>
) => undefined | Response | Promise<undefined | Response>;
export type PRECHECKS_TABLE = Record<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', PRECHECK>;
export type PRECHECKS_TABLE = Record<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', PRECHECK[]>;
export type ROUTE_HANDLER_METHOD = (request: Request, meta: Record<string, any>) => Promise<Response> | Response;
export interface ROUTE_HANDLER {
@ -73,7 +73,7 @@ export interface ROUTE_HANDLER {
A default exported method will be called for any unspecified methods and can
decide what to do with the request itself.
`PRECHECKS` can defined a precheck per-method, eg: `PRECHECKS.GET = ( request, meta ) => ...`
`PRECHECKS` can defined a precheck per-method, eg: `PRECHECKS.GET = [( request, meta ) => ...]`
A precheck method should return a `Response` if there's an error that should stop
the request from proceeding. For example, if you require a session for a given route,
@ -82,6 +82,11 @@ session, perhaps adding it to the `meta` data that will be passed to the `GET`
handler itself. If there is no session, however, it should return an HTTP `Response`
object indicating permission is denied or similar.
## TODO
- [ ] reload typescript if it is modified on disk
#### NOTE ON WINDOWS
Because Windows has more restrictions on filenames, you can use `___` in place of `:` in