Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Oct 30, 2025

Summary

Implements issue #508 to allow treating links references as binary data, enabling the doublets store to function as a file system, archive, or file storage database.

Changes

1. New Extension Methods (ILinksExtensions.cs)

Added EnsureReferenceExistsOrExternal methods that validate references while allowing external (binary data) references:

public static void EnsureReferenceExistsOrExternal<TLinkAddress>(
    this ILinks<TLinkAddress> links, 
    TLinkAddress reference, 
    string argumentName)

Behavior:

  • ✅ Internal references → validated for existence (throws if not found)
  • ✅ External references → allowed without validation (binary data)

2. New Decorator: LinksExternalReferenceValidator

Created LinksExternalReferenceValidator<TLinkAddress> decorator that:

  • Overrides Each(), Update(), and Delete() methods
  • Uses EnsureReferenceExistsOrExternal() for validation
  • Enables mixed usage of internal (existing links) and external (binary data) references

Location: csharp/Platform.Data.Doublets/Decorators/LinksExternalReferenceValidator.cs

3. Comprehensive Test Suite

Added 7 tests in LinksExternalReferenceValidatorTests.cs (all passing ✅):

  1. InternalReferenceValidationTest - Ensures internal references must exist
  2. ExternalReferenceAllowedTest - Verifies external references work without validation
  3. MixedInternalAndExternalReferencesTest - Tests combined usage
  4. EachOperationWithExternalReferencesTest - Validates query operations
  5. DeleteOperationValidationTest - Confirms delete still validates existence
  6. ComparisonWithInnerReferenceValidatorTest - Demonstrates differences between validators
  7. BinaryDataStorageScenarioTest - Real-world file system use case

Key Features

External Reference Support via Hybrid Type

Uses Hybrid<T> with isExternal: true to mark references as binary data:

var binaryData = new Hybrid<ulong>(0xDEADBEEF, isExternal: true);
var link = validator.Update(existingLink, source, binaryData);

Use Cases Enabled

  • File System: Store file metadata as binary references
  • Archive Storage: Variable-length reference sequences
  • Binary Database: Raw data storage alongside graph structure
  • Hybrid Data: Mix internal graph links with external binary pointers

Testing

Local Tests: ✅ All 7 tests passing
CI Status: ✅ Passing (auto-merge workflow succeeded)

Implementation Details

Validation Logic

// From EnsureReferenceExistsOrExternal
if (links.Constants.IsInternalReference(reference) && !links.Exists(reference))
{
    throw new ArgumentLinkDoesNotExistsException<TLinkAddress>(reference, argumentName);
}
// External references pass through without validation

Decorator Pattern

Follows existing pattern from LinksInnerReferenceExistenceValidator:

  • Inherits from LinksDecoratorBase<TLinkAddress>
  • Wraps ILinks<TLinkAddress> implementation
  • Provides transparent validation layer

Backwards Compatibility

Fully backwards compatible

  • Existing code using LinksInnerReferenceExistenceValidator continues to work
  • New LinksExternalReferenceValidator is opt-in
  • No breaking changes to API or behavior

Related


🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: undefined
@konard konard self-assigned this Oct 30, 2025
…s as binary data

Implements issue #508 by creating a new validator that accepts both internal and external references:
- Internal references (existing links) are validated for existence
- External references (binary data via Hybrid type) are allowed without validation

Changes:
1. Added EnsureReferenceExistsOrExternal extension methods to ILinksExtensions.cs
   - Validates internal references must exist in store
   - Allows external references (binary data) without existence checking

2. Created LinksExternalReferenceValidator decorator
   - Similar structure to LinksInnerReferenceExistenceValidator
   - Uses new EnsureReferenceExistsOrExternal validation methods
   - Enables doublets store to be used as file system/binary data storage

3. Added comprehensive test suite (7 tests, all passing)
   - Tests internal reference validation
   - Tests external reference support
   - Tests mixed internal/external references
   - Tests Each, Update, and Delete operations
   - Demonstrates real-world binary data storage scenario

This enables variable-length reference sequences and allows the doublets store
to function as a file system, archive, or file storage database as described in issue #508.

Fixes #508

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Allow treat links references as binary data Allow treating links references as binary data Oct 30, 2025
@konard konard marked this pull request as ready for review October 30, 2025 04:27
@konard
Copy link
Member Author

konard commented Oct 30, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

📎 Log file uploaded as GitHub Gist (653KB)
🔗 View complete solution draft log


Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

Allow treat links references as binary data

2 participants