Skip to content

Commit

Permalink
feat: ReturnedSchema handles isArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorikairox committed Nov 7, 2024
1 parent 52cbd7b commit 28898a5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,31 @@ export function Query<T extends z.ZodRawShape>(zodSchema: z.ZodObject<T>): Decor
*/
export const RETURNED_SCHEMA_KEY = 'returnschema';

type MethodDecoratorFunction = (
// deno-lint-ignore ban-types
target: Object,
propertyKey?: string | symbol,
descriptor?: PropertyDescriptor,
) => void;

/**
* Decorator to set metadata for the returned zod schema of a method.
*
* @param returnedSchema - The type of the value that the method or property returns.
* @param isArray
*/
export function ReturnedSchema<T extends z.ZodRawShape>(returnedSchema: z.ZodObject<T>): DecoratorFunction {
export function ReturnedSchema(returnedSchema: any, isArray?: boolean): MethodDecoratorFunction {
return (
target: Object,
propertyKey?: string | symbol,
descriptor?: any,
) => {
MetadataHelper.setMetadata(
RETURNED_SCHEMA_KEY,
returnedSchema,
{
returnedSchema,
isArray,
},
target,
propertyKey,
);
Expand Down

0 comments on commit 28898a5

Please sign in to comment.