chore(core): refactor reflection helpers into PropertyReflection and ConstructReflection classes#37352
Merged
mergify[bot] merged 1 commit intomainfrom Apr 8, 2026
Merged
Conversation
3261856 to
fd49b53
Compare
fd49b53 to
e54a4ec
Compare
e54a4ec to
78578c1
Compare
kumsmrit
approved these changes
Apr 8, 2026
packages/aws-cdk-lib/core/lib/helpers-internal/property-reflection.ts
Outdated
Show resolved
Hide resolved
packages/aws-cdk-lib/core/lib/helpers-internal/property-reflection.ts
Outdated
Show resolved
Hide resolved
Contributor
|
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). |
2958e13 to
704ac5c
Compare
Contributor
Author
|
@Mergifyio queue |
Contributor
Merge Queue Status
This pull request spent 14 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
Contributor
|
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). |
Contributor
|
Comments on closed issues and PRs are hard for our team to see. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for this change
The generic reflection helpers in
core/lib/helpers-internal/reflections.tswere 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.
PropertyReflectionprovides token-aware property inspection onCfnResourceinstances. A singleof(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 separateresolvedGet/resolvedExists/resolvedEqualsfunctions that each re-traversed the path independently. The traversal now treatsnullthe same asundefined(both are "missing") for consistency.ConstructReflectionprovides construct tree search utilities.ConstructReflection.of(construct)creates an instance, then.findCfnResource(matcher)and.findRelatedCfnResource(matcher)search for CfnResources using a sharedICfnResourceMatcherinterface. ThedefaultChildOwnergetter replaces the oldfindParentL2Scopefunction. 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
CfnKeyMatcherclass inaws-kms/lib/private/.All internal consumers are updated. The old
reflections.tsfile 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) coversPropertyReflection, andconstruct-reflection.test.ts(17 tests) coversConstructReflection. Thebucket-reflection.test.tssuite (32 tests) continues to provide integration-level coverage throughBucketReflection.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license