Skip to content

Feature/sync client - #18

Merged
MaximilianRau04 merged 4 commits into
mainfrom
feature/sync-client
Aug 24, 2026
Merged

MaximilianRau04 merged 4 commits into
mainfrom
feature/sync-client

Conversation

@priyanshuvishwakarma273403

Copy link
Copy Markdown
Collaborator

Overview

This PR implements the client-side synchronization infrastructure for docsgraph. It introduces a production-ready HTTP client communicating with docsgraph-server's sync endpoints and an orchestrator (SyncManager) that manages local-to-remote pushing/pulling, handles offline gracefully, and automatically resumes on reconnection.

Key Changes

1. HTTP Sync Client (packages/data/src/sync/client.ts)

  • Implemented HttpSyncClient implementing SyncClient using native fetch.
  • Connects to standard docsgraph-server sync endpoints:
    • POST /api/v1/sync/push
    • GET /api/v1/sync/pull?since=<cursor>
  • Added support for bearer authentication using either a static token or a dynamic evaluation function () => string | null.

2. Sync Manager Orchestration (packages/data/src/sync/manager.ts)

  • Created SyncManager coordinating data exchange between LocalStore and SyncClient.
  • Workflow:
    1. Push Phase: Detects and pushes unsynced local mutations.
    2. Pull Phase: Fetches remote operations starting from the local cursor, applying them using the store's conflict resolution logic, and updates the local cursor.
  • Offline Handling: Gracefully catches fetch failures, transitioning state to offline instead of crashing.
  • Reconnection Handling: Subscribes to browser online events to automatically retry sync cycles when connectivity is restored. Includes a configurable polling fallback.
  • Avoided any typings entirely to satisfy strict ESLint rules.

3. Verification & Testing (packages/data/src/sync/sync.test.ts)

  • Added comprehensive unit tests covering:
    • HttpSyncClient API request body, params, and header validation.
    • SyncManager lifecycle (Happy path pushing/pulling, offline graceful degradation on fetch failure, and automatic retry on online events).
  • Safely mocked global window, navigator, and fetch properties using property descriptor overrides to ensure compatibility with strict environments (Node.js/JSDOM).

Verification Results

All tests and code checks run successfully locally:

  • pnpm lint: Passed (0 warnings/errors)
  • pnpm test: Passed (12/12 tests)

@MaximilianRau04 MaximilianRau04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push result is never applied, so ack tracking is dead code. Works today by accident, not by design.

Comment thread packages/data/src/sync/manager.ts Resolved

@MaximilianRau04 MaximilianRau04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: push result now flows into applyAck with correct op_id/seq, and the client types match docsgraph-server's actual contract. Approving.

@MaximilianRau04
MaximilianRau04 merged commit 6040f17 into main Aug 24, 2026
1 check passed
@MaximilianRau04
MaximilianRau04 deleted the feature/sync-client branch August 24, 2026 13:28
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