Skip to content

Feat/add support for status endpoint#10

Merged
andinux merged 10 commits intodevfrom
feat/add-support-for-status-endpoint
Mar 4, 2026
Merged

Feat/add support for status endpoint#10
andinux merged 10 commits intodevfrom
feat/add-support-for-status-endpoint

Conversation

@andinux
Copy link

@andinux andinux commented Mar 4, 2026

  • feat(network): add support for new status endpoint
  • refactor(network): structured JSON responses for sync functions. Example: {"send":{"status":"synced","localVersion":5,"serverVersion":5},"receive":{"rows":3,"tables":["tasks"]}}

- automatically update the latest sent db_version value after sending payloads depending on the status returned by the cloudsync http service
- the cloudsync_network_send_changes functions now returns the status data in the json format
- the cloudsync_network_has_unsent_changes now call the status endpoints before comparing with the latest local db_version
- only consider the db_version value in the WHERE clause of cloudsync_payload_get, don't filter at seq level
The three public sync functions was leaking internal server JSON or returning raw integers. We want them to return coherent, user-facing JSON with a computed status field and relevant version/row info.

New responses:
 - cloudsync_network_send_changes — formats JSON: {"status":"...", "localVersion":N, "serverVersion":N}
 - cloudsync_network_check_changes — formats JSON: {"rowsReceived":N}
  -  cloudsync_network_sync — combines send + check results into: {"status":"...", "localVersion":N, "serverVersion":N, "rowsReceived":N}

The status helper computes "synced", "syncing", "retry", or "error" from the apply/status response fields.
…nd/receive keys

Change the flat JSON return format of network functions to a nested
structure with "send" and "receive" top-level keys, rename
"rowsReceived" to "rows" for conciseness, and add a "tables" array
field to the receive section listing affected table names.

Before: {"status":"synced","localVersion":5,"serverVersion":5,"rowsReceived":3}
After:  {"send":{"status":"synced","localVersion":5,"serverVersion":5},"receive":{"rows":3,"tables":["tasks"]}}

Update integration tests to use SQLite's ->> operator for JSON field
extraction, and add db_expect_str helper for string assertions.
…ayload AND db_version == 0.

1. Added early return for empty-db case (lines 959–966): When there's no payload (blob == NULL || blob_size == 0) AND db_version == 0, skip the network call entirely and return { server_version: 0, local_version: 0, status: "synced" }. This avoids the 404 from the status endpoint when the server doesn't know the device yet.
2. Fixed condition from || to && (line 969): Changed blob != NULL || blob_size > 0 to blob != NULL && blob_size > 0 — both conditions must be true to confirm there's actual data to upload.
@andinux andinux merged commit 00692a2 into dev Mar 4, 2026
17 checks passed
@andinux andinux deleted the feat/add-support-for-status-endpoint branch March 4, 2026 22:02
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.

1 participant