-
Notifications
You must be signed in to change notification settings - Fork 9
feat(runner): createDataCellURI with circular reference detection and relative link rewriting #1917
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
Conversation
Avoid writing data: URI links to storage by inlining their contents before persisting. This prevents storage bloat and ensures data URIs are treated as ephemeral values rather than persistent references. Changes: - Add findAndInlineDataURILinks() to recursively inline data: URIs - Call inlining in Cell.setRaw() before writing values - Call inlining in normalizeAndDiff() when processing links - Preserve schema when following links within data URIs - Handle nested links and paths within data URI contents The inlining process: 1. Detects links with data: URI IDs 2. Extracts and decodes the embedded JSON value 3. Follows any nested links found within the data 4. Returns the final inlined value for storage This ensures data URIs are always expanded to their actual values before being written to storage, avoiding unnecessary indirection and preventing data: URIs from accumulating in the database. Tests added in data-uri-inlining.test.ts cover all inlining scenarios including nested structures, links within data URIs, and schema preservation.
…relative link rewriting Moves `createDataCellURI` helper from test file into `link-utils.ts` and adds two key features: 1. **Circular data detection**: Throws an error when encountering circular references, preventing JSON.stringify failures and providing clear error messages. 2. **Relative link rewriting**: When a base cell/link is provided, rewrites all internal relative links to include the base's id, ensuring links remain valid when embedded in data URIs. Includes comprehensive test coverage for both features, including edge cases with nested structures and arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 3 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="packages/runner/src/link-utils.ts">
<violation number="1" location="packages/runner/src/link-utils.ts:525">
Cycle detection keeps every visited object in the shared Set, so reusing the same (acyclic) object elsewhere now throws "Cycle detected" even though JSON.stringify can serialize it. Please track only the current recursion path or remove entries when unwinding.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
Previously, cycle detection kept every visited object in the shared Set, causing false positives when reusing the same acyclic object elsewhere. Now properly removes objects from the Set when unwinding recursion. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 2 files
Moves
createDataCellURIhelper from test file intolink-utils.tsandadds two key features:
Circular data detection: Throws an error when encountering circular
references, preventing JSON.stringify failures and providing clear error
messages.
Relative link rewriting: When a base cell/link is provided, rewrites
all internal relative links to include the base's id, ensuring links
remain valid when embedded in data URIs.
Includes comprehensive test coverage for both features, including edge cases
with nested structures and arrays.
Summary by cubic
Added createDataCellURI to link-utils to safely build data: URIs. It detects circular references and rewrites relative links with a base id so embedded links remain valid.
New Features
Refactors