generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 180
Closed
Labels
bugSomething isn't workingSomething isn't workingconfirmedThe scope is clear, ready for implementationThe scope is clear, ready for implementation
Description
Expected Behavior
The type inferred for DynamoDBStreamRecord (schema) should include e.g. SequenceNumber.
| SequenceNumber: z.string(), |
Current Behavior
The inferred type seems to be the lowest common denominator of:
powertools-lambda-typescript/packages/parser/src/schemas/dynamodb.ts
Lines 31 to 32 in bccd0b1
| | z.infer<typeof DynamoDBStreamChangeRecordBase> | |
| | z.infer<typeof DynamoDBStreamToKinesisChangeRecord>, |
powertools-lambda-typescript/packages/parser/src/schemas/dynamodb.ts
Lines 22 to 27 in bccd0b1
| const DynamoDBStreamToKinesisChangeRecord = DynamoDBStreamChangeRecordBase.omit( | |
| { | |
| SequenceNumber: true, | |
| StreamViewType: true, | |
| } | |
| ); |
Code snippet
import {
DynamoDBStreamRecord as DynamoDBStreamRecordSchema,
} from '@aws-lambda-powertools/parser/schemas/dynamodb';
type DynamoDBStreamRecord = z.infer<typeof DynamoDBStreamRecordSchema>;Steps to Reproduce
- Write the above code snippet.
- Hover over the
DynamoDBStreamRecordtype to see it does not include e.g.dynamodb.SequenceNumber.
Possible Solution
Define the dynamodb field as a union e.g.
// Make the function generic so we can force particular return types.
const unmarshallDynamoDBTransform = <T extends z.infer<typeof DynamoDBStreamChangeRecordBase> | z.infer<typeof DynamoDBStreamToKinesisChangeRecord>>(
object: T,
ctx: z.RefinementCtx
): T => { ... }
// Specialise `DynamoDBStreamChangeRecord` to the full / base type.
const DynamoDBStreamChangeRecord = DynamoDBStreamChangeRecordBase.transform(
unmarshallDynamoDBTransform<z.infer<typeof DynamoDBStreamChangeRecordBase>>
);
// Add a further type to accommodate the "ToKinesis" version.
const DynamoDBStreamToKinesisChangeRecord = DynamoDBStreamChangeRecordBase.transform(
unmarshallDynamoDBTransform<z.infer<typeof DynamoDBStreamToKinesisChangeRecord>>
);
// Define `dynamodb field as a union.
const DynamoDBStreamRecord = z.object({
...,
dynamodb: z.union([DynamoDBStreamChangeRecord, DynamoDBStreamToKinesisChangeRecord]),
...,
});Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingconfirmedThe scope is clear, ready for implementationThe scope is clear, ready for implementation
Type
Projects
Status
Coming soon