Skip to content

Commit

Permalink
feat: query and body stored in different metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorikairox committed Oct 17, 2024
1 parent edb6d31 commit 61f2a92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { NotValidBodyException, createParamDecorator, OptionsResolver, type Exec
import { z } from "zod";
import { MetadataHelper } from '@danet/core/metadata';

export const zodSchemaKey = 'zodSchema'
/**
* Constant to access body zod schema for metadata
*/
export const zodBodySchemaKey = 'zodBodySchema'

/**
* Constant to access query zod schema for metadata
*/
export const zodQuerySchemaKey = 'zodQuerySchema'

/**
* Get request's body or a given property and validate it with the provided Zod Schema. Throws NotValidBodyException
Expand Down Expand Up @@ -34,7 +42,7 @@ export function Body<T extends z.ZodRawShape>(zodSchema: z.ZodObject<T>, prop?:
return param;
}, (target, propertyKey) => {
MetadataHelper.setMetadata(
zodSchemaKey,
zodBodySchemaKey,
zodSchema,
target.constructor,
propertyKey,
Expand All @@ -56,7 +64,7 @@ export function Query<T extends z.ZodRawShape>(zodSchema: z.ZodObject<T>): Decor
return param;
}, (target, propertyKey) => {
MetadataHelper.setMetadata(
zodSchemaKey,
zodQuerySchemaKey,
zodSchema,
target.constructor,
propertyKey,
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@danet/zod",
"version": "0.0.4",
"version": "0.0.5",
"exports": {
".": "./decorators.ts"
},
Expand Down

0 comments on commit 61f2a92

Please sign in to comment.