Skip to content

feat: let serialize BaseGraph with Codecs#778

Merged
tbouffard merged 1 commit intomainfrom
feat/add_BaseGraph_Codec
Apr 25, 2025
Merged

feat: let serialize BaseGraph with Codecs#778
tbouffard merged 1 commit intomainfrom
feat/add_BaseGraph_Codec

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Apr 25, 2025

Covers #760

Summary by CodeRabbit

  • New Features
    • Introduced support for serializing and deserializing BaseGraph instances.
  • Refactor
    • Improved test coverage by consolidating and parameterizing graph serialization tests.
    • Streamlined the management of excluded fields in graph serialization codecs for better maintainability.
  • Chores
    • Updated internal exports and registration logic to include the new BaseGraph serialization codec.

@tbouffard tbouffard added the enhancement New feature or request label Apr 25, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This update introduces a new BaseGraphCodec class for handling serialization and deserialization of BaseGraph instances, with specific fields excluded from the process. The exclusion list for GraphCodec is refactored into a reusable exported constant. The registration process for codecs is updated to include BaseGraphCodec. The test suite for serialization codecs is refactored to use parameterized tests, allowing shared logic to be tested across both Graph and BaseGraph classes. Export statements are adjusted to accommodate the new codec and improve module clarity.

Changes

File(s) Change Summary
packages/core/src/serialization/codecs/BaseGraphCodec.ts Added new BaseGraphCodec class for serializing/deserializing BaseGraph with specified excluded fields.
packages/core/src/serialization/codecs/GraphCodec.ts Extracted excluded fields into exported constant excludedFields; refactored constructor to use this constant.
packages/core/src/serialization/codecs/_other-codecs.ts Added export for BaseGraphCodec; changed GraphCodec export from wildcard to named export.
packages/core/src/serialization/register-other-codecs.ts Imported and registered BaseGraphCodec in the codec registry within registerCoreCodecs.
packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts Refactored tests to use parameterized suite for Graph and BaseGraph; added utility function for XML generation; updated imports.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant GraphClass (Graph/BaseGraph)
    participant Codec (GraphCodec/BaseGraphCodec)
    participant CodecRegistry

    TestSuite->>GraphClass: Create instance
    TestSuite->>Codec: Serialize GraphClass instance
    Codec->>TestSuite: Return XML
    TestSuite->>Codec: Import XML to GraphClass instance
    Codec->>GraphClass: Populate fields from XML
    TestSuite->>GraphClass: Verify properties
Loading

Possibly related PRs


📜 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 ee74226 and 29193e7.

📒 Files selected for processing (5)
  • packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (3 hunks)
  • packages/core/src/serialization/codecs/BaseGraphCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/GraphCodec.ts (2 hunks)
  • packages/core/src/serialization/codecs/_other-codecs.ts (1 hunks)
  • packages/core/src/serialization/register-other-codecs.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
packages/core/src/serialization/register-other-codecs.ts (1)
packages/core/src/serialization/codecs/BaseGraphCodec.ts (1)
  • BaseGraphCodec (37-42)
packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (3)
packages/core/__tests__/utils.ts (1)
  • createGraphWithoutContainer (25-25)
packages/core/src/view/plugins/index.ts (1)
  • getDefaultPlugins (46-55)
packages/core/src/index.ts (1)
  • AbstractGraph (20-20)
packages/core/src/serialization/codecs/BaseGraphCodec.ts (1)
packages/core/src/serialization/codecs/GraphCodec.ts (1)
  • excludedFields (22-31)
packages/core/src/serialization/codecs/GraphCodec.ts (1)
packages/core/src/view/Graph.ts (1)
  • Graph (41-102)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: build (macos-14)
🔇 Additional comments (15)
packages/core/src/serialization/register-other-codecs.ts (2)

19-19: Added import for BaseGraphCodec.

The new import for BaseGraphCodec is correctly added alongside other codec imports.


81-81: BaseGraphCodec registration added.

The BaseGraphCodec is now registered in the registerCoreCodecs function, enabling serialization support for BaseGraph instances. The placement before GraphCodec registration is appropriate since BaseGraph is the parent class of Graph.

packages/core/src/serialization/codecs/_other-codecs.ts (2)

18-18: Added export for BaseGraphCodec.

The export statement for the new BaseGraphCodec is properly added.


21-21: Changed export style for GraphCodec.

The export style for GraphCodec has been changed from a wildcard export to a named export. This is a good practice that explicitly states what's being exported and aligns with the need to export the excludedFields constant separately.

packages/core/src/serialization/codecs/GraphCodec.ts (2)

22-31: Extracted excluded fields into a reusable constant.

Good refactoring to extract the excluded fields list into a separate exported constant. This follows the DRY principle and allows the list to be reused in the new BaseGraphCodec, ensuring consistency in what fields are excluded from serialization.


53-53: Updated constructor to use the extracted constant.

The constructor now correctly uses the excludedFields constant instead of an inline array.

packages/core/src/serialization/codecs/BaseGraphCodec.ts (3)

1-20: New BaseGraphCodec implementation with proper imports and documentation.

The new file includes appropriate copyright header, imports, and JSDoc documentation for the codec. Importing the excludedFields from GraphCodec demonstrates good code reuse.


21-36: Well-documented codec class.

The JSDoc documentation correctly lists all the transient fields that will be excluded from serialization, which helps developers understand what parts of BaseGraph instances won't be included when serialized.


37-42: BaseGraphCodec implementation.

The BaseGraphCodec class correctly extends ObjectCodec and is implemented similarly to the GraphCodec class. The constructor properly initializes with a new BaseGraph instance and reuses the excludedFields constant from GraphCodec.

packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (6)

17-17: LGTM: Updated imports to support parameterized testing.

The imports have been correctly updated to include describe from Jest globals, which is necessary for the parameterized test structure used later in the file.


23-24: LGTM: Added required imports for BaseGraph testing.

Properly imported BaseGraph and getDefaultPlugins to support the new codec functionality being tested.


52-82: Well-designed XML template function.

Good refactoring to extract the XML template into a reusable function that dynamically substitutes the graph type name. This eliminates code duplication and makes the tests more maintainable.


84-90: LGTM: Clear test parameterization for both graph types.

The parameterized test structure is well-designed, covering both Graph (using the existing factory function) and BaseGraph (with default plugins) implementations.


91-98: LGTM: Export test verifies correct serialization.

The export test properly verifies that both graph types serialize correctly, with appropriate property overrides to ensure the serialization process captures changes from defaults.


100-113: LGTM: Import test verifies correct deserialization.

The import test effectively verifies the deserialization process by:

  1. Checking default property values before import
  2. Performing the import operation
  3. Verifying that properties were correctly overridden with values from the XML

This provides good test coverage for the codec functionality.

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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.

@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit 3a1dc00 into main Apr 25, 2025
7 checks passed
@tbouffard tbouffard deleted the feat/add_BaseGraph_Codec branch April 25, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant