Skip to content

Fix entity with Json field set to the mock db#565

Merged
DZakh merged 3 commits into
mainfrom
dz/fix-mock-db-json-set
Jun 5, 2025
Merged

Fix entity with Json field set to the mock db#565
DZakh merged 3 commits into
mainfrom
dz/fix-mock-db-json-set

Conversation

@DZakh

@DZakh DZakh commented Jun 4, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added a new event handler that processes events to create entities with all supported data types.
  • Bug Fixes
    • Improved event handling logic by making case handling more explicit.
  • Tests
    • Added a comprehensive test to verify correct processing and storage of entities with all field types.
  • Refactor
    • Simplified and unified entity storage logic by removing index maintenance and using linear scans for queries.

@DZakh DZakh requested a review from JonoPrest June 4, 2025 11:41
@coderabbitai

coderabbitai Bot commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update removes explicit index management from the mock database code, replacing index-based lookups with linear scans and simplifying function signatures to use entity configuration records. Additionally, it introduces a new event handler and test that processes and verifies entities with all supported data types in the test scenario.

Changes

File(s) Change Summary
codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs Removed index management logic, switched to linear scans, simplified function signatures to use entityConfig, unified entity execution.
scenarios/test_codegen/src/EventHandlers.ts Added a new event handler for "entityWithAllTypesSet" test case; updated contract register handler to use explicit case.
scenarios/test_codegen/test/EventHandler_test.ts Added a test verifying the event handler correctly stores entities with all supported data types.

Sequence Diagram(s)

sequenceDiagram
    participant EventHandler
    participant Context
    participant MockDb

    EventHandler->>Context: set EntityWithAllTypes (twice)
    Context->>MockDb: Store entities in memory
    Note over MockDb: No index management, linear scan on retrieval
Loading

Possibly related PRs

Suggested reviewers

  • JonoPrest

Poem

In the warren of code, a change hops through,
Indices gone, now scans will do.
Entities of every type, set with glee,
In memory they rest, index-free.
A handler hops in, tests run anew—
🐇 Cheers to the code, and to all types too!


📜 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 98f43b7 and a397bad.

📒 Files selected for processing (1)
  • scenarios/test_codegen/test/EventHandler_test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scenarios/test_codegen/test/EventHandler_test.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
✨ 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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1cbe0 and 98f43b7.

📒 Files selected for processing (3)
  • codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs (6 hunks)
  • scenarios/test_codegen/src/EventHandlers.ts (1 hunks)
  • scenarios/test_codegen/test/EventHandler_test.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
scenarios/test_codegen/test/EventHandler_test.ts (1)
codegenerator/cli/templates/static/codegen/index.js (1)
  • BigDecimal (7-7)
scenarios/test_codegen/src/EventHandlers.ts (1)
codegenerator/cli/templates/static/codegen/index.js (1)
  • BigDecimal (7-7)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (10)
scenarios/test_codegen/src/EventHandlers.ts (2)

424-426: Good change to use explicit case instead of default.

Replacing the default case with an explicit case "syncRegistration" improves code clarity and makes the expected behavior more predictable.


430-478: Comprehensive test handler for entity types.

The new event handler provides excellent coverage for testing all supported data types. The implementation correctly uses BigDecimal constructors and covers all field variations (required, optional, and arrays).

scenarios/test_codegen/test/EventHandler_test.ts (2)

4-4: Necessary import for BigDecimal usage.

The BigDecimal import is correctly added to support the new test case.


107-151: Well-structured test for comprehensive entity handling.

The test effectively validates that the event handler correctly creates entities with all supported data types. Good use of the spread operator to verify the second entity and proper type assertions with satisfies.

codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs (6)

107-120: Simplified delete operation looks correct.

The removal of index management code simplifies the delete operation while maintaining the core functionality for the mock database.


122-136: Streamlined set operation.

The simplified set operation correctly handles entity updates without the overhead of index maintenance, which is appropriate for a mock database used in testing.


282-292: Appropriate simplification for mock database queries.

The switch from index-based lookups to linear scans is a reasonable simplification for the mock database. The filtering logic using Index.evaluate maintains consistency with the expected behavior while reducing complexity.


302-303: Clean refactoring of executeRowsEntity.

The simplified function signature using entityConfig improves code clarity and reduces parameter passing overhead.

Also applies to: 307-307, 318-318


337-337: Good optimization to cache table reference.

Caching the mockDbTable reference avoids repeated lookups during iteration, improving performance.

Also applies to: 342-342


367-372: Elegant simplification using centralized entity configuration.

Replacing individual entity execution calls with a loop over Config.codegenPersistence.allEntities provides better maintainability and automatically handles all entity types without manual enumeration.

Comment thread scenarios/test_codegen/test/EventHandler_test.ts Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Comment on lines -406 to -413
//ENTITY EXECUTION
{{#each entities as | entity |}}
mockDb->executeRowsEntity(
~inMemoryStore,
~entityMod=module(Entities.{{entity.name.capitalized}}),
~getKey=entity => entity.id,
)
{{/each}}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, do we still need a .hbs file?

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing!

@DZakh DZakh enabled auto-merge (squash) June 5, 2025 10:26
@DZakh DZakh merged commit 074bef0 into main Jun 5, 2025
2 checks passed
@DZakh DZakh deleted the dz/fix-mock-db-json-set branch June 5, 2025 10:36
This was referenced Oct 29, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Nov 7, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Dec 5, 2025
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