-
Notifications
You must be signed in to change notification settings - Fork 154
Feature request: export Records
schema building blog for customizations
#2811
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
Comments
Hi @am29d, this is a good point and we should definitely expose these schemas. My only concern is with where to export them. On one hand I see the value of exposing them in the main barrel file both for consistency and relative ease of usage. On the other hand, I think we should help customers do the right thing and instead provide scoped exports. Even when using ESM with tree-shaking enabled, using the barrel file causes all the schemas to be pulled in into the bundle. This is because Exporting schemas in their own subpath export like we started doing with API Gateway-related schemas would instead allow customers to target a specific group of schemas and bring in only these. I don't have concrete data to back this up, but I would imagine that customers won't be using more than a handful built-in schemas in each function. If this is true, then giving scoped exports will help to keep their bundle size small, especially as we add more and more specialized schemas. So in short, I am in favor of exporting these schemas as they improve the DX, but I would suggest we do this responsibly and provide subpath exports for each service. |
I agree, I have seen your changes for API gateway and we should change other exports as well, i.e.: before import { SqsSchema } from '@aws-lambda-powertools/parser/schemas'; after import { SqsSchema } from '@aws-lambda-powertools/parser/schemas/sqs'; |
@am29d @dreamorosi Should i take this issue first then? :) |
@daschaa of course, all yours :) |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This is now released under v2.7.0 version! |
Use case
When you want to extend the built-in schema with your custom schema you can extend the it and overwrite specific parts with of the built-in schema we provide.
The
body
value isz.string()
in theAlbSchema
and we can plug in modifications.This works for schemas with first the modifiable attribute available in the main schema, such as
AlbSchema
,EventBrdigeSchema
or others.When working with schemas that contain a list of elements the
body
part is not accessible, thus customers can't extend it without replicating the entireRecord
. For example, theSqsEvent
is:To overwrite the body, we'd need:
Solution/User Experience
Export the record elements that are nested parts of the built-in schema. For SQS it would be
powertools-lambda-typescript/packages/parser/src/schemas/sqs.ts
Lines 26 to 38 in 1e7175a
This would allow us change only the body field
The requirement for nested
Records
exports applies to:While some of this objects are exported in their own files, they are not part of the barrel export and thus customers can't import them.
Alternative solutions
No response
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: