Support serializing/deserializing empty arrays
Closes #1174
✅ Checklist
- [x] I have followed every step in the contributing guide
- [x] The PR title follows the convention.
- [ ] I ran and tested the code works
Testing
Struggling to get re2 to build to properly test this, will try on another setup. I added unit testing for the serializing portion.
Changelog
This allows empty arrays to be serialized and deserialized. This is important for debugging, to properly show the difference between no value and an empty array.
Screenshots
N/a
💯
Follow ups: probably the same behavior for empty objects?
Summary by CodeRabbit
-
New Features
- Enhanced data handling to ensure that empty arrays are consistently processed and represented, improving data accuracy and rendering within the application.
-
Tests
- Added comprehensive tests to verify the correct treatment of empty array scenarios, bolstering overall data reliability and quality assurance.
Walkthrough
The changes introduce a new constant, EMPTY_ARRAY_SENTINEL, across multiple modules to improve handling of empty arrays. Both the rehydrateJson function in the webapp and the flattening/unflattening logic in the core have been updated to use this sentinel. Additionally, the export set has been augmented to include the new constant, and new test cases have been added to validate the handling of empty arrays. Existing checks for null and NULL_SENTINEL remain unchanged.
Changes
| File(s) | Change Summary |
|---|---|
apps/.../taskEvent.ts apps/.../eventRepository.server.ts |
Added EMPTY_ARRAY_SENTINEL and updated rehydrateJson with a conditional check to return an empty array when the sentinel value is encountered. |
packages/core/src/v3/index.ts |
Added a new export for EMPTY_ARRAY_SENTINEL from ./utils/flattenAttributes.js. |
packages/core/src/v3/utils/flattenAttributes.ts |
Introduced EMPTY_ARRAY_SENTINEL; updated flattenAttributes to set the sentinel for empty arrays; renamed rehydrateNull to rehydrateEmptyValues to properly rehydrate empty arrays. |
packages/core/test/flattenAttributes.test.ts |
Added new test cases to validate the flattening and unflattening of empty arrays, with minor formatting updates. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant Flattener
participant Unflattener
Caller->>Flattener: Send data containing an empty array
Note right of Flattener: Detect empty array and use EMPTY_ARRAY_SENTINEL
Flattener-->>Caller: Return flattened data with sentinel
Caller->>Unflattener: Send flattened data
Note left of Unflattener: Convert EMPTY_ARRAY_SENTINEL back to an empty array
Unflattener-->>Caller: Return original data with empty array
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Ensure run log outputs display empty arrays correctly (#1174 [TRI-2755]) | ✅ |
Possibly related PRs
-
triggerdotdev/trigger.dev#1433: Modifies
rehydrateJsonto useEMPTY_ARRAY_SENTINEL, enhancing empty array handling. - triggerdotdev/trigger.dev#1432: Updates the flattening and unflattening functions to process sentinel values for empty arrays.
Poem
I'm just a rabbit hopping through the code,
Found a little sentinel lightening my load.
Empty arrays now show up crystal clear,
With rehydration magic, they appear!
Carrots and clean code, a joyful blend,
Hopping in celebration until the very end! 🥕
📜 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 db03d25228095c82fef28987c2c826986400f401 and ded7c4aa74b72e36f3dc69f39e22f181c180208c.
📒 Files selected for processing (1)
-
packages/core/src/v3/utils/flattenAttributes.ts(6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/v3/utils/flattenAttributes.ts
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai planto trigger planning for file edits and PR creation. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
⚠️ No Changeset found
Latest commit: ded7c4aa74b72e36f3dc69f39e22f181c180208c
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
This is great! Can you try and do the same for empty objects in this PR too?