Skip to content

chore(runtime): replace traverse dependency #2160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 24, 2025
Merged

Conversation

DoctorFTB
Copy link
Contributor

Replace traverse dependency as it has over 60+ dependencies..

You can find the change history in the commits.
Feel free to squash commits.

Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

📝 Walkthrough

Walkthrough

The changes replace usage of the external traverse library with a new locally implemented simpleTraverse utility for object traversal within the codebase. The new function is introduced, exported, and integrated into relevant modules, with traversal callback signatures and update mechanisms adapted accordingly. No public API signatures are changed.

Changes

File(s) Change Summary
packages/runtime/src/local-helpers/simple-traverse.ts Introduced simpleTraverse utility for recursive object traversal with update and cycle detection.
packages/runtime/src/local-helpers/index.ts Added export for simpleTraverse from ./simple-traverse.
packages/runtime/src/enhancements/node/delegate.ts Replaced traverse usage with simpleTraverse in sanitizeMutationPayload; updated callback signature.
packages/runtime/src/enhancements/node/policy/policy-utils.ts Replaced traverse with simpleTraverse in PolicyUtil methods; updated traversal and update logic.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant simpleTraverse
    participant Callback

    Caller->>simpleTraverse: Call with (root, cb)
    loop For each node in object tree
        simpleTraverse->>Callback: cb({ path, key, value, update })
        alt Callback calls update
            Callback-->>simpleTraverse: update(newValue)
            simpleTraverse-->>simpleTraverse: Replace node value, skip children
        else Callback does not call update
            simpleTraverse-->>simpleTraverse: Continue traversal into children
        end
    end
    simpleTraverse-->>Caller: Return updated root object
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce850db and 41ca3cc.

📒 Files selected for processing (1)
  • packages/runtime/src/local-helpers/simple-traverse.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/runtime/src/local-helpers/simple-traverse.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: dependency-review
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ed36bb and 184aa74.

⛔ Files ignored due to path filters (2)
  • packages/runtime/package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
📒 Files selected for processing (4)
  • packages/runtime/src/enhancements/node/delegate.ts (2 hunks)
  • packages/runtime/src/enhancements/node/policy/policy-utils.ts (2 hunks)
  • packages/runtime/src/local-helpers/index.ts (1 hunks)
  • packages/runtime/src/local-helpers/simple-traverse.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build-test (20.x)
  • GitHub Check: build-test (20.x)
  • GitHub Check: OSSAR-Scan
  • GitHub Check: build-test (20.x)
  • GitHub Check: dependency-review
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: GitGuardian Security Checks
🔇 Additional comments (7)
packages/runtime/src/local-helpers/simple-traverse.ts (2)

23-31: Review update function behavior

The update function correctly prevents further traversal when called (keepGoing = false) and only allows updates when there's a parent. The logic looks sound for preventing infinite loops during updates.


17-18: Verify circular reference detection logic

The circular reference detection compares object identity using ===. This should work correctly for detecting when the same object appears multiple times in the traversal path.

#!/bin/bash
# Search for any existing circular reference handling patterns in the codebase
rg -A 3 -B 3 "circular|cycle" --type ts
packages/runtime/src/local-helpers/index.ts (1)

1-1: LGTM: Clean export addition

The export follows the established pattern and makes simpleTraverse available to other modules in the codebase.

packages/runtime/src/enhancements/node/delegate.ts (1)

16-16: Verify import path and availability

Ensure the simpleTraverse import is correctly resolved from the local helpers.

#!/bin/bash
# Verify the simpleTraverse function is properly exported and can be imported
fd "index.ts" packages/runtime/src/local-helpers/ --exec cat {}
packages/runtime/src/enhancements/node/policy/policy-utils.ts (3)

17-17: LGTM: Clean dependency replacement

Good addition of the local simpleTraverse utility to replace the external traverse dependency.


705-712: Clean conversion of delegate constraint resolution

The conversion from traverse(result).forEach() to simpleTraverse(result, callback) maintains the same logic for resolving delegate constraints. The destructured callback parameters { value, update } provide a clean API.


693-703: ```shell
#!/bin/bash

Locate all occurrences of simpleTraverse to find its implementation

rg -n "simpleTraverse" -C5 packages/runtime/src


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@DoctorFTB DoctorFTB marked this pull request as draft June 21, 2025 13:17
@DoctorFTB DoctorFTB marked this pull request as ready for review June 21, 2025 14:24
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

Thanks @DoctorFTB , LGTM!

@ymc9 ymc9 merged commit a069003 into zenstackhq:dev Jun 24, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants