Skip to content

Feature request: implement parser decorator #1816

Closed
@am29d

Description

@am29d

Use case

Similar to middy middleware we want to use build-in schemas and envelopes to parse and extract events using decorators.

Solution/User Experience

Based on the RFC the decorator should take model and envelope as an param object:

const order = z.object({
  id: z.number(),
  description: z.string(),
});

type Order = z.infer<typeof order>;

class Lambda implements LambdaInterface {
  // Decorate your handler class method
  @logger.injectLambdaContext()
  @parser({eventBridgeEnvelope, order})
  public async handler(
    _event: OrderModel,
    _context: Context
  ): Promise<void> {
    logger.info(`Received order model ${_event}`);
  }
}

we should also be able to pass only the model, which can be a custom event or an extension of the built-in schema i.e.

const order = z.object({
  id: z.number(),
  description: z.string(),
});

const customEBschema = EventBridgeSchema.extend({
  detail: order,
});

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