Skip to content

Feature request: implement schema envelopes #1791

Closed
@am29d

Description

@am29d

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

Future readers

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

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilityparserThis item relates to the Parser Utility

Type

No type

Projects

Status

Shipped

Relationships

None yet

Development

No branches or pull requests

Issue actions