Comparing version 1.3.8 to 1.4.0
import { Context, Middleware } from "koa"; | ||
import { HTTPMethod } from "../@types/http"; | ||
import { Response } from "../@types/response"; | ||
@@ -11,4 +10,3 @@ import { AnySchema } from "yup"; | ||
}; | ||
export declare type Route<RequestSchema = AnySchema, ResponseBody = {}, URLParams = {}> = ({ | ||
method: HTTPMethod; | ||
export declare type Route<RequestSchema = AnySchema, ResponseBody = {}, URLParams = {}> = { | ||
handler: (context: ParameterizedContext<RequestSchema extends AnySchema ? RequestSchema["__outputType"] : null, URLParams>) => Promise<Response<ResponseBody>>; | ||
@@ -19,4 +17,4 @@ middleware?: { | ||
}; | ||
}) & (RequestSchema extends AnySchema ? { | ||
} & (RequestSchema extends AnySchema ? { | ||
validation: RequestSchema; | ||
} : {}); |
@@ -35,3 +35,3 @@ "use strict"; | ||
middleware.forEach(app.use); | ||
const registerRoute = (path, { method, handler, middleware }) => { | ||
const registerRoute = (path, { handler, middleware }) => { | ||
const { pre = [], post = [] } = middleware || {}; | ||
@@ -44,3 +44,3 @@ const middlewareChain = [...pre, handler, ...post].map((func) => { | ||
}); | ||
router[method](path, ...middlewareChain); | ||
router.all(path, ...middlewareChain); | ||
}; | ||
@@ -47,0 +47,0 @@ for (const { getRoute, path } of (0, filesystem_1.mapDirectoryToRoutes)(routesFolder)) |
import { Route, ParameterizedContext } from "../@types/router"; | ||
export declare const handleRoute: (route: Route) => { | ||
method: import("../@types/http").HTTPMethod; | ||
handler: (context: ParameterizedContext) => Promise<void>; | ||
@@ -5,0 +4,0 @@ middleware: { |
@@ -29,3 +29,2 @@ "use strict"; | ||
return { | ||
method: route.method, | ||
handler, | ||
@@ -32,0 +31,0 @@ middleware: route.middleware |
import { Context, Middleware } from "koa"; | ||
import { HTTPMethod } from "@/@types/http"; | ||
import { Response } from "@/@types/response"; | ||
@@ -13,6 +12,9 @@ | ||
request: Context["request"] & { body?: RequestSchemaOutputType }; | ||
} | ||
}; | ||
export type Route<RequestSchema = AnySchema, ResponseBody = {}, URLParams = {}> = ({ | ||
method: HTTPMethod; | ||
export type Route< | ||
RequestSchema = AnySchema, | ||
ResponseBody = {}, | ||
URLParams = {} | ||
> = { | ||
handler: ( | ||
@@ -24,7 +26,7 @@ context: ParameterizedContext< | ||
) => Promise<Response<ResponseBody>>; | ||
middleware?: { | ||
pre?: Middleware[]; | ||
post?: Middleware[]; | ||
} | ||
}) & (RequestSchema extends AnySchema | ||
middleware?: { | ||
pre?: Middleware[]; | ||
post?: Middleware[]; | ||
}; | ||
} & (RequestSchema extends AnySchema | ||
? { | ||
@@ -31,0 +33,0 @@ validation: RequestSchema; |
@@ -39,3 +39,3 @@ import Koa, { Context, Next } from "koa"; | ||
path: string, | ||
{ method, handler, middleware }: Route | ||
{ handler, middleware }: Route | ||
) => { | ||
@@ -50,3 +50,3 @@ const { pre = [], post = [] } = middleware || {}; | ||
router[method](path, ...middlewareChain); | ||
router.all(path, ...middlewareChain); | ||
}; | ||
@@ -53,0 +53,0 @@ |
@@ -27,3 +27,2 @@ import { Route, ParameterizedContext } from "@/@types/router"; | ||
return { | ||
method: route.method, | ||
handler, | ||
@@ -30,0 +29,0 @@ middleware: route.middleware |
{ | ||
"name": "18h", | ||
"description": "A Next.js style dynamic API router for Koa-based APIs.", | ||
"version": "1.3.8", | ||
"version": "1.4.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "https://github.com/ridafkih/18h" |
@@ -30,3 +30,2 @@ # 18h | ||
const handler: Route<{}, { success: boolean }, { userId: string }> = { | ||
method: "post", | ||
async handler(context) { | ||
@@ -33,0 +32,0 @@ const success = await deleteUserById(context.params.userId); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20014
20
454
64