Skip to content

Commit

Permalink
fix stupid types
Browse files Browse the repository at this point in the history
  • Loading branch information
ridafkih committed Oct 15, 2022
1 parent b1a5c01 commit 9cab332
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 4 additions & 5 deletions lib/@types/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Context } from "koa";
import type { ZodNull, infer as ZodInfer } from "zod";
import type {
NonNullableValidStructure,
ValidStructure,
} from "@/@types/valid-structure";

interface OverrideBody<T extends Record<string, unknown> | undefined> extends Exclude<Context["request"], "body"> {
Expand All @@ -14,7 +13,7 @@ interface OverrideRequest<T extends Record<string, unknown> | undefined> extends
}

export type ExtendedContext<
RequestBody extends ValidStructure = ZodNull,
RequestBody = ZodNull,
URLParams extends Record<string, string> = Record<string, never>
> = OverrideRequest<
RequestBody extends NonNullableValidStructure
Expand All @@ -25,7 +24,7 @@ export type ExtendedContext<
};

type MethodContext<
RequestSchema extends ValidStructure,
RequestSchema,
URLParams extends Record<string, string> = Record<string, never>
> = ExtendedContext<RequestSchema, URLParams>;

Expand All @@ -42,8 +41,8 @@ type MethodHandlerFunctionResponse<ResponseSchema> =
};

export type MethodHandlerFunction<
RequestSchema extends ValidStructure,
ResponseSchema extends ValidStructure,
RequestSchema,
ResponseSchema,
URLParams extends Record<string, string>
> = (
context: MethodContext<RequestSchema, URLParams>
Expand Down
8 changes: 4 additions & 4 deletions lib/src/create-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
type MiddlewareStack = Array<Middleware>;

export type CreateMethodOptions<
RequestSchema extends ValidStructure,
ResponseSchema extends ValidStructure,
RequestSchema,
ResponseSchema,
URLParams extends Record<string, string>
> = {
schema: {
Expand All @@ -35,8 +35,8 @@ export type CreateMethodOptions<
* @returns The method object.
*/
export const method = <
ResponseSchema extends ValidStructure,
RequestSchema extends ValidStructure,
ResponseSchema,
RequestSchema,
URLParams extends Record<string, string>
>(
options: CreateMethodOptions<RequestSchema, ResponseSchema, URLParams>
Expand Down
8 changes: 5 additions & 3 deletions lib/src/create-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import type { ValidStructure } from "@/@types/valid-structure";
* @returns An object containing the methods.
*/
export const route = <
URLParams extends Record<string, string> = Record<string, never>
URLParams extends Record<string, string> = Record<string, never>,
RequestBody extends ValidStructure = ValidStructure,
ResponseBody extends ValidStructure = ValidStructure
>(methods: {
[K in MethodName]?: CreateMethodOptions<
ValidStructure,
ValidStructure,
RequestBody,
ResponseBody,
URLParams
>;
}) => methods;

0 comments on commit 9cab332

Please sign in to comment.