Skip to content

Conversation

@benthorner
Copy link
Contributor

@benthorner benthorner commented Nov 25, 2025

Summary

Changes

Please provide a summary of what's being changed

This fixes a DynamoDB Stream record Zod schema typing issue.

Before:

// z.infer<typeof DynamoDBStreamChangeRecord[Schema]>
dynamodb: {
    Keys: Record<string, Record<string, any>>;
    SizeBytes: number;
    ApproximateCreationDateTime?: number | undefined;
    NewImage?: Record<string, any> | undefined;
    OldImage?: Record<string, any> | undefined;
};

After:

dynamodb: {
    Keys: Record<string, Record<string, any>>;
    SequenceNumber: string;
    SizeBytes: number;
    StreamViewType: "NEW_IMAGE" | "OLD_IMAGE" | "NEW_AND_OLD_IMAGES" | "KEYS_ONLY";
    ApproximateCreationDateTime?: number | undefined;
    NewImage?: Record<string, any> | undefined;
    OldImage?: Record<string, any> | undefined;
} | {
    Keys: Record<string, Record<string, any>>;
    SizeBytes: number;
    ApproximateCreationDateTime?: number | undefined;
    NewImage?: Record<...> | undefined;
    OldImage?: Record<...> | undefined;
};

The "before" type is preserved for the Kinesis-only version of the
schema. As part of this change, we internally suffix Schema for
all properties in schemas/dynamodb.ts, which unblocks naming
some types to support the main fix - see the first commit.

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: closes #4797

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@boring-cyborg boring-cyborg bot added the parser This item relates to the Parser Utility label Nov 25, 2025
@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Nov 25, 2025
@benthorner benthorner changed the title Fix DynamoDBStreamChangeRecordSchema.dynamodb type feat(parser): fix DynamoDBStreamChangeRecordSchema.dynamodb type Nov 25, 2025
As discussed in [^1], this helps avoid conflict when referring to
schemas and inferred schema types in the same file.

We alias the exports to avoid breaking third party imports.

[^1]: aws-powertools#4797 (comment)
Before:

  // z.infer<typeof DynamoDBStreamChangeRecordSchema>
  dynamodb: {
      Keys: Record<string, Record<string, any>>;
      SizeBytes: number;
      ApproximateCreationDateTime?: number | undefined;
      NewImage?: Record<string, any> | undefined;
      OldImage?: Record<string, any> | undefined;
  };

After:

  dynamodb: {
      Keys: Record<string, Record<string, any>>;
      SequenceNumber: string;
      SizeBytes: number;
      StreamViewType: "NEW_IMAGE" | "OLD_IMAGE" | "NEW_AND_OLD_IMAGES" | "KEYS_ONLY";
      ApproximateCreationDateTime?: number | undefined;
      NewImage?: Record<string, any> | undefined;
      OldImage?: Record<string, any> | undefined;
  } | {
      Keys: Record<string, Record<string, any>>;
      SizeBytes: number;
      ApproximateCreationDateTime?: number | undefined;
      NewImage?: Record<...> | undefined;
      OldImage?: Record<...> | undefined;
  };

This converts `unmarshallDynamoDBTransform` to a generic function
and specifies the expected type for both usages.
@sonarqubecloud
Copy link

@svozza
Copy link
Contributor

svozza commented Nov 25, 2025

Nice ork @benthorner! LGTM.

@benthorner
Copy link
Contributor Author

Thanks for taking a look @svozza! I notice the CI seems to be a bit stuck - anything I can help with?

@svozza svozza changed the title feat(parser): fix DynamoDBStreamChangeRecordSchema.dynamodb type feat(parser): fix DynamoDBStreamChangeRecordSchema.dynamodb type Nov 25, 2025
@sdangol sdangol merged commit bf522f8 into aws-powertools:main Nov 25, 2025
48 checks passed
@svozza
Copy link
Contributor

svozza commented Nov 25, 2025

Looks like @sdangol got in before me! All sorted @benthorner, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parser This item relates to the Parser Utility size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Inferred type for DynamoDBStreamRecord (schema) is incorrect

3 participants