Skip to content

chore(core): refactor reflection helpers into PropertyReflection and ConstructReflection classes#37352

Merged
mergify[bot] merged 1 commit intomainfrom
mrgrain/chore/construct-reflections
Apr 8, 2026
Merged

chore(core): refactor reflection helpers into PropertyReflection and ConstructReflection classes#37352
mergify[bot] merged 1 commit intomainfrom
mrgrain/chore/construct-reflections

Conversation

@mrgrain
Copy link
Copy Markdown
Contributor

@mrgrain mrgrain commented Mar 25, 2026

Reason for this change

The generic reflection helpers in core/lib/helpers-internal/reflections.ts were a collection of loosely related free functions (resolvedGet, resolvedExists, resolvedEquals, findClosestRelatedResource, findL1FromRef, findParentL2Scope). The naming used L1/L2 jargon, the signatures were inconsistent between functions, and the property traversal logic was duplicated three times. The free-function style also made it harder to discover the available reflection capabilities.

Description of changes

This refactors the reflection helpers into two focused classes with a consistent API shape, each in its own file.

PropertyReflection provides token-aware property inspection on CfnResource instances. A single of(resource, path) call traverses the dot-separated path once, and the result can be queried with .exists(), .equals(expected), or .get(fallback). This replaces the three separate resolvedGet/resolvedExists/resolvedEquals functions that each re-traversed the path independently. The traversal now treats null the same as undefined (both are "missing") for consistency.

ConstructReflection provides construct tree search utilities. ConstructReflection.of(construct) creates an instance, then .findCfnResource(matcher) and .findRelatedCfnResource(matcher) search for CfnResources using a shared ICfnResourceMatcher interface. The defaultChildOwner getter replaces the old findParentL2Scope function. The method signatures are aligned and jsii-compatible — no generics on the public API, and the matcher interface can be implemented in any jsii language.

The duplicated KMS key matching logic (identical across S3, DynamoDB, SQS, and SNS) is extracted into a private CfnKeyMatcher class in aws-kms/lib/private/.

All internal consumers are updated. The old reflections.ts file is deleted.

Describe any new or updated permissions being added

None.

Description of how you validated changes

All existing tests pass. The test file is split to match the new file structure: property-reflection.test.ts (33 tests) covers PropertyReflection, and construct-reflection.test.ts (17 tests) covers ConstructReflection. The bucket-reflection.test.ts suite (32 tests) continues to provide integration-level coverage through BucketReflection.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team March 25, 2026 14:52
@github-actions github-actions bot added the p2 label Mar 25, 2026
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 25, 2026
@mrgrain mrgrain force-pushed the mrgrain/chore/construct-reflections branch from 3261856 to fd49b53 Compare March 25, 2026 14:54
@mrgrain mrgrain force-pushed the mrgrain/chore/construct-reflections branch from fd49b53 to e54a4ec Compare March 25, 2026 15:28
@mrgrain mrgrain marked this pull request as ready for review March 27, 2026 11:35
@mrgrain mrgrain requested a review from a team as a code owner March 27, 2026 11:35
@mrgrain mrgrain force-pushed the mrgrain/chore/construct-reflections branch from e54a4ec to 78578c1 Compare March 27, 2026 11:46
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Mar 27, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 8, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mrgrain mrgrain force-pushed the mrgrain/chore/construct-reflections branch from 2958e13 to 704ac5c Compare April 8, 2026 15:33
@mrgrain
Copy link
Copy Markdown
Contributor Author

mrgrain commented Apr 8, 2026

@Mergifyio queue

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 8, 2026

Merge Queue Status

  • Entered queue2026-04-08 16:19 UTC · Rule: default-squash
  • Checks skipped · PR is already up-to-date
  • Merged2026-04-08 16:19 UTC · at 704ac5cca37b8e07479388bbdb466f9b630bf34c

This pull request spent 14 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 8, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 1b4496f into main Apr 8, 2026
23 checks passed
@mergify mergify bot deleted the mrgrain/chore/construct-reflections branch April 8, 2026 16:19
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2026
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Apr 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants