Closed
Description
Use case
Similar to the python implementation we want to have reusable envelopes that we can extend with custom schema.
Solution/User Experience
Envelopes encapsulate the provided custom model in a built-in schema. This means that they parse specific part of the event detail
for EventBridge or body
for SQS.
const eventBridgeEnvelope = (<T extends ZodSchema>(data: unknown, schema: T) => {
return schema.parse(EventBridgeSchema.parse(data).detail);
});
This will allow us to bring your own custom schema:
const customSchema = z.object({
foo: z.string()
})
type CustomSchema = z.infer<typeof customSchema>;
const customEventBridgeEvent: CustomSchema = eventBridgeEnvelope({foo: 'bar'}, customSchema);
While is a one line, it'd be great to provide a bit more debug logs around both calls. It's worth emphasise that envelopes do not return schemas, but the parsed object of the custom schema.
Alternative solutions
No response
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped