Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: allow parser set event type of handler with middy #2407

Open
2 tasks done
yamatatsu opened this issue Apr 21, 2024 · 1 comment
Open
2 tasks done
Labels
discussing The issue needs to be discussed, elaborated, or refined feature-request This item refers to a feature request for an existing or new utility

Comments

@yamatatsu
Copy link
Contributor

Use case

middy can pass event type like as this. So we can pass inferred event type from zod schema to handler.

Solution/User Experience

const detailSchema = z.object({
	date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
	message: z.string(),
});

export const handler = middy()
	// when using parser
	.use(parser({ schema: detailSchema, envelope: EventBridgeEnvelope }))
	// handler will get event type already inferred without type annotation.
	.handler(async (event) => {
		logger.inf(event.detail.message)
	});

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

@yamatatsu yamatatsu added triage This item has not been triaged by a maintainer, please wait feature-request This item refers to a feature request for an existing or new utility labels Apr 21, 2024
@yamatatsu yamatatsu changed the title Feature request: allow parser set event type of handler with meddy Feature request: allow parser set event type of handler with middy Apr 21, 2024
@am29d
Copy link
Contributor

am29d commented Apr 22, 2024

Hey @yamatatsu, thanks for raising the issue.

In your example, I think you missed the types in the middy() call. Can you modify the solution code block to reflect that? In the meantime, I will investigate how we could add event types to middy call.

Edit: now that Andrea pointed out to me, I got your point more clearly. You want to infer the type in the handler if it comes after the parser. I'd need to investigate a bit more what it will take to implement it.

@am29d am29d added discussing The issue needs to be discussed, elaborated, or refined and removed triage This item has not been triaged by a maintainer, please wait labels Apr 22, 2024
@dreamorosi dreamorosi added this to the Parser - GA Release milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussing The issue needs to be discussed, elaborated, or refined feature-request This item refers to a feature request for an existing or new utility
Projects
Development

No branches or pull requests

3 participants