diff --git a/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts b/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts index 572e2d9d..85dc56ab 100644 --- a/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts +++ b/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts @@ -1,8 +1,7 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { DocumentVersion } from "./DocumentVersion"; import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutContent"; /** * Response to an update document request. */ -export type DocumentUpdateResponse = { "type": "Accepted" } & DocumentVersionWithoutContent | { "type": "StaleBase" } & DocumentVersion; +export type DocumentUpdateResponse = { "type": "Accepted" } & DocumentVersionWithoutContent | { "type": "StaleBase" } & DocumentVersionWithoutContent; diff --git a/frontend/sync-client/src/services/types/EventBatch.ts b/frontend/sync-client/src/services/types/EventBatch.ts index f17f17ed..a3bfb573 100644 --- a/frontend/sync-client/src/services/types/EventBatch.ts +++ b/frontend/sync-client/src/services/types/EventBatch.ts @@ -1,4 +1,8 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { EventRecord } from "./EventRecord"; -export type EventBatch = { headEventId: number, events: Array, }; +export type EventBatch = { headEventId: number, +/** + * Last event in this page; `head_event_id` is the vault's current head. + */ +endEventId?: number, events: Array, }; diff --git a/frontend/sync-client/src/services/types/WebSocketHandshake.ts b/frontend/sync-client/src/services/types/WebSocketHandshake.ts index 85c2cf0d..310c0bb8 100644 --- a/frontend/sync-client/src/services/types/WebSocketHandshake.ts +++ b/frontend/sync-client/src/services/types/WebSocketHandshake.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type WebSocketHandshake = { token: string, deviceId: string, lastSeenVaultUpdateId: number | null, }; +export type WebSocketHandshake = { token: string, deviceId: string, }; diff --git a/frontend/sync-client/src/services/types/WebSocketServerMessage.ts b/frontend/sync-client/src/services/types/WebSocketServerMessage.ts index 2a7a7813..c9759e04 100644 --- a/frontend/sync-client/src/services/types/WebSocketServerMessage.ts +++ b/frontend/sync-client/src/services/types/WebSocketServerMessage.ts @@ -1,5 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { CursorPositionFromServer } from "./CursorPositionFromServer"; -import type { EventBatch } from "./EventBatch"; -export type WebSocketServerMessage = { "type": "vaultEvents" } & EventBatch | { "type": "cursorPositions" } & CursorPositionFromServer; +export type WebSocketServerMessage = { "type": "vaultChanged" } | { "type": "cursorPositions" } & CursorPositionFromServer; diff --git a/sync-server/src/app_state/database/models.rs b/sync-server/src/app_state/database/models.rs index 57c4cd94..5330a8dc 100644 --- a/sync-server/src/app_state/database/models.rs +++ b/sync-server/src/app_state/database/models.rs @@ -123,5 +123,11 @@ pub struct VaultSnapshot { pub struct EventBatch { #[ts(as = "f64")] pub head_event_id: VaultUpdateId, + + /// Last event in this page; `head_event_id` is the vault's current head. + #[serde(skip_serializing_if = "Option::is_none")] + #[ts(optional, as = "Option")] + pub end_event_id: Option, + pub events: Vec, } diff --git a/sync-server/src/app_state/websocket/models.rs b/sync-server/src/app_state/websocket/models.rs index 32d97966..4eb1fa10 100644 --- a/sync-server/src/app_state/websocket/models.rs +++ b/sync-server/src/app_state/websocket/models.rs @@ -1,16 +1,13 @@ use serde::{Deserialize, Serialize}; use ts_rs::TS; -use crate::app_state::database::models::{DeviceId, DocumentId, EventBatch, VaultUpdateId}; +use crate::app_state::database::models::{DeviceId, DocumentId, VaultUpdateId}; #[derive(TS, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct WebSocketHandshake { pub token: String, pub device_id: DeviceId, - - #[ts(as = "Option")] - pub last_seen_vault_update_id: Option, } #[derive(TS, Deserialize, Clone, Debug)] @@ -67,6 +64,6 @@ pub enum WebSocketClientMessage { #[serde(rename_all = "camelCase", tag = "type")] #[ts(export)] pub enum WebSocketServerMessage { - VaultEvents(EventBatch), + VaultChanged, CursorPositions(CursorPositionFromServer), } diff --git a/sync-server/src/server/responses.rs b/sync-server/src/server/responses.rs index 66c5b5cb..e8d85687 100644 --- a/sync-server/src/server/responses.rs +++ b/sync-server/src/server/responses.rs @@ -2,7 +2,7 @@ use serde::{self, Deserialize, Serialize}; use ts_rs::TS; use crate::app_state::database::models::{ - DocumentVersion, DocumentVersionWithoutContent, FileManifest, VaultUpdateId, + DocumentVersionWithoutContent, FileManifest, VaultUpdateId, }; /// Response to a ping request. @@ -34,7 +34,7 @@ pub enum DocumentUpdateResponse { Accepted(DocumentVersionWithoutContent), /// Nothing was written. The client must incorporate this version before retrying. - StaleBase(DocumentVersion), + StaleBase(DocumentVersionWithoutContent), } #[derive(TS, Debug, Clone, Serialize, Deserialize)]