Skip to content

Commit

Permalink
feat: make it works well with latest Deno
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorikairox committed Sep 22, 2024
1 parent ae79f26 commit 3ef86cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions decorators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NotValidBodyException, createParamDecorator, OptionsResolver, type HttpContext } from './deps.ts';
import { NotValidBodyException, createParamDecorator, OptionsResolver, type ExecutionContext } from './deps.ts';
import { z } from "https://deno.land/x/zod/mod.ts";

export const ZodBody = (zodSchema: any, prop?: string) => createParamDecorator(async (context: HttpContext, opts?: OptionsResolver) => {
export const ZodBody = <T extends z.ZodRawShape>(zodSchema: z.ZodObject<T>, prop?: string) => createParamDecorator(async (context: ExecutionContext, opts?: OptionsResolver) => {
if (!opts) {
throw {
status: 500,
Expand All @@ -27,7 +28,7 @@ export const ZodBody = (zodSchema: any, prop?: string) => createParamDecorator(a
})();


export const ZodQuery = (zodSchema: any) => createParamDecorator(async (context: HttpContext, opts?: OptionsResolver) => {
export const ZodQuery = <T extends z.ZodRawShape>(zodSchema: z.ZodObject<T>) => createParamDecorator(async (context: ExecutionContext, opts?: OptionsResolver) => {
const param = context.req.query()
const operation = zodSchema.safeParse(param);
if (!operation.success) {
Expand Down
8 changes: 8 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { DanetApplication, type HttpContext } from 'https://deno.land/x/danet/mod.ts';
export { DanetApplication, type ExecutionContext } from 'https://deno.land/x/danet/mod.ts';
export { MetadataHelper } from 'https://deno.land/x/danet/src/metadata/mod.ts';
export { NotValidBodyException } from 'https://deno.land/x/danet/src/exception/http/exceptions.ts';
export { createParamDecorator, type OptionsResolver } from 'https://deno.land/x/danet/src/router/controller/params/decorators.ts';

0 comments on commit 3ef86cf

Please sign in to comment.