Skip to content

Conversation

@seefeldb
Copy link
Contributor

@seefeldb seefeldb commented Oct 17, 2025

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.


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

    • Throws on circular data to prevent JSON.stringify failures.
    • Rewrites relative links to include the base cell/link id (when provided).
  • Refactors

    • Moved the test-only helper into link-utils.ts and exported it for reuse.

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.
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 &quot;Cycle detected&quot; 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>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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

@seefeldb seefeldb merged commit 03b3a10 into main Oct 17, 2025
9 checks passed
@seefeldb seefeldb deleted the feat/create-data-cell-uris branch October 17, 2025 18:39
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