Skip to content

fix(core): cached Lazys use the Box API internally#37889

Merged
mergify[bot] merged 2 commits into
mainfrom
mrgrain/refactor/core/lazy-extends-box
May 18, 2026
Merged

fix(core): cached Lazys use the Box API internally#37889
mergify[bot] merged 2 commits into
mainfrom
mrgrain/refactor/core/lazy-extends-box

Conversation

@mrgrain
Copy link
Copy Markdown
Contributor

@mrgrain mrgrain commented May 15, 2026

Issue # (if applicable)

N/A

Reason for this change

We don't want multiple deferred value APIs that behave differently. With this change, Lazy acts as a backwards-compatible user-facing front, but internally it's all Box API. One resolution mechanism, one set of behaviors.

Description of changes

Introduces LazyBox, a ReadonlyState wrapper that makes cached Lazy tokens participate in the Box ecosystem. Cached Lazy methods (Lazy.string(), Lazy.number(), Lazy.list(), Lazy.any()) now return a LazyBox that passes Box.isBox() and supports derive() and getStackTraces().

Uncached Lazy methods remain unchanged — they depend on resolution context and cannot be boxes (at least for now).

Splits ReadonlyState out of State in box.ts to provide an immutable base for LazyBox.

Describe any new or updated permissions being added

N/A

Description of how you validated changes

Added tests in boxes.test.ts verifying that cached Lazy variants are boxes and uncached variants are not. Tests cover Box.isBox(), resolve(), derive(), and caching semantics. All existing tests (including nested-stack) continue to pass.

Checklist


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

@mrgrain mrgrain requested a review from a team as a code owner May 15, 2026 12:40
@github-actions github-actions Bot added the p2 label May 15, 2026
@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label May 15, 2026
@mergify mergify Bot temporarily deployed to automation May 15, 2026 12:40 Inactive
@mergify mergify Bot temporarily deployed to automation May 15, 2026 12:41 Inactive
@mrgrain mrgrain changed the title refactor(core): make Lazy tokens extend Box State fix(core): make Lazy tokens extend Box State May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

👋 It looks like your PR description follows the template but is missing a valid issue number in the first section.

PRs without a linked issue will receive lower priority for review and merging. Please update the description to include a reference like Closes #123. If no existing issue matches your change, create one first.

@mrgrain mrgrain changed the title fix(core): make Lazy tokens extend Box State fix(core): Lazy now uses the Box API internally May 15, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@mrgrain mrgrain added pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels May 15, 2026
@aws-cdk-automation aws-cdk-automation dismissed their stale review May 15, 2026 12:43

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@mrgrain mrgrain changed the title fix(core): Lazy now uses the Box API internally fix(core): cached Lazys now use the Box API internally May 15, 2026
@mrgrain mrgrain changed the title fix(core): cached Lazys now use the Box API internally fix(core): cached Lazys use the Box API internally May 15, 2026
@mrgrain mrgrain force-pushed the mrgrain/refactor/core/lazy-extends-box branch from 8565bff to 7d83d36 Compare May 15, 2026 17:42
Comment thread packages/aws-cdk-lib/core/lib/lazy.ts Outdated
@otaviomacedo otaviomacedo added the pr/do-not-merge This PR should not be merged at this time. label May 15, 2026
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 15, 2026
Refactor LazyBase to extend State from the Box API, making all Lazy
tokens pass Box.isBox(). This enables PropertyAssignmentMetadataWriter
to detect Lazy tokens and allows Lazy values to participate in the
Box derive/combine ecosystem.

Export State and BaseReadableBox from box.ts. Add Box.empty() factory.
Add tests verifying Lazy tokens are boxes with correct resolve, derive,
and caching behavior.
@mrgrain mrgrain force-pushed the mrgrain/refactor/core/lazy-extends-box branch from 7d83d36 to 96ba2cd Compare May 18, 2026 10:09
@mrgrain mrgrain removed the pr/do-not-merge This PR should not be merged at this time. label May 18, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 18, 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
Copy link
Copy Markdown
Contributor

mergify Bot commented May 18, 2026

Merge Queue Status

  • Entered queue2026-05-18 10:40 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-05-18 12:01 UTC · at 6eec03f37af94241b8af684f3a0cd7c638c02747 · squash

This pull request spent 1 hour 21 minutes 24 seconds in the queue, including 39 minutes 30 seconds running CI.

Required conditions to merge

@mergify mergify Bot temporarily deployed to automation May 18, 2026 11:21 Inactive
@mergify mergify Bot temporarily deployed to automation May 18, 2026 11:21 Inactive
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 18, 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 464fa3d into main May 18, 2026
19 of 20 checks passed
@mergify mergify Bot deleted the mrgrain/refactor/core/lazy-extends-box branch May 18, 2026 12:01
@github-actions
Copy link
Copy Markdown
Contributor

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 May 18, 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 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants