11import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types' ;
22import type { Context , Handler } from 'aws-lambda' ;
3- import { ZodSchema , z } from 'zod' ;
3+ import { type ZodSchema } from 'zod' ;
44import { parse } from './parser.js' ;
5- import type { ParserOptions , ParsedResult } from './types/index.js' ;
5+ import type { ParserOptions , Envelope } from './types/index.js' ;
6+ import type { ParserOutput } from './types/parser.js' ;
67
78/**
89 * A decorator to parse your event.
@@ -67,8 +68,12 @@ import type { ParserOptions, ParsedResult } from './types/index.js';
6768 *
6869 * @param options Configure the parser with the `schema`, `envelope` and whether to `safeParse` or not
6970 */
70- export const parser = < S extends ZodSchema > (
71- options : ParserOptions < S >
71+ export const parser = <
72+ TSchema extends ZodSchema ,
73+ TEnvelope extends Envelope = undefined ,
74+ TSafeParse extends boolean = false ,
75+ > (
76+ options : ParserOptions < TSchema , TEnvelope , TSafeParse >
7277) : HandlerMethodDecorator => {
7378 return ( _target , _propertyKey , descriptor ) => {
7479 const original = descriptor . value ! ;
@@ -77,14 +82,11 @@ export const parser = <S extends ZodSchema>(
7782
7883 descriptor . value = async function (
7984 this : Handler ,
80- event : unknown ,
85+ event : ParserOutput < TSchema , TEnvelope , TSafeParse > ,
8186 context : Context ,
8287 callback
8388 ) {
84- const parsedEvent : ParsedResult <
85- typeof event ,
86- z . infer < typeof schema >
87- > = parse ( event , envelope , schema , safeParse ) ;
89+ const parsedEvent = parse ( event , envelope , schema , safeParse ) ;
8890
8991 return original . call ( this , parsedEvent , context , callback ) ;
9092 } ;
0 commit comments