From 544e370f1941e56e4805649eb03a96e70dc7abd0 Mon Sep 17 00:00:00 2001 From: Kevin Whitley Date: Fri, 29 Mar 2024 14:37:32 -0500 Subject: [PATCH] router matchup fixed? --- example/router-matchup.ts | 4 ++++ src/AutoRouter.ts | 5 ++--- src/types/AutoRouterType.ts | 13 +++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/router-matchup.ts b/example/router-matchup.ts index be510bb..2e7ab96 100644 --- a/example/router-matchup.ts +++ b/example/router-matchup.ts @@ -17,6 +17,10 @@ autorouter.get('/throw', (a) => a.b.c) router.get('/throw', (a) => a.b.c) ittyrouter.get('/throw', (a) => a.b.c) +// autorouter tests +autorouter.missing +autorouter.format + // test response formatting const autorouterResponse = (await autorouter.fetch(request)).foo const routerResponse = (await router.fetch(request)).foo diff --git a/src/AutoRouter.ts b/src/AutoRouter.ts index 7ba4470..e239920 100644 --- a/src/AutoRouter.ts +++ b/src/AutoRouter.ts @@ -1,9 +1,8 @@ import { Router } from './Router' import { error } from './error' import { json } from './json' -import { AutoRouterOptions, AutoRouterType, RouterType } from './types' +import { AutoRouterOptions, AutoRouterType, IRequest } from './types' import { withParams } from './withParams' -import { IRequest } from './types' export const AutoRouter = < RequestType extends IRequest = IRequest, @@ -15,7 +14,7 @@ export const AutoRouter = < finally: f = [], before = [], ...options }: AutoRouterOptions = {} -): RouterType => Router({ +): AutoRouterType => Router({ before: [ withParams, ...before diff --git a/src/types/AutoRouterType.ts b/src/types/AutoRouterType.ts index 4268f1f..1921c81 100644 --- a/src/types/AutoRouterType.ts +++ b/src/types/AutoRouterType.ts @@ -1,16 +1,13 @@ -import { ErrorHandler } from './ErrorHandler' import { IRequest } from './IRequest' import { RequestHandler } from './RequestHandler' import { ResponseHandler } from './ResponseHandler' import { RouterType } from './RouterType' -// export type AutoRouterType< -// R = IRequest, -// Args extends any[] = any[], -// ResponseType = any -// > = (options?: AutoRouterOptions) => RouterType - -export type AutoRouterType = { +export type AutoRouterType< + R = IRequest, + Args extends any[] = any[], + ResponseType = any +> = { missing?: RequestHandler format?: ResponseHandler } & RouterType