Simplify API

This commit is contained in:
Andras Schmelczer 2026-09-22 20:26:02 +01:00
commit c9ce7fe4db
7 changed files with 18 additions and 13 deletions

View file

@ -1,8 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // 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"; import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutContent";
/** /**
* Response to an update document request. * Response to an update document request.
*/ */
export type DocumentUpdateResponse = { "type": "Accepted" } & DocumentVersionWithoutContent | { "type": "StaleBase" } & DocumentVersion; export type DocumentUpdateResponse = { "type": "Accepted" } & DocumentVersionWithoutContent | { "type": "StaleBase" } & DocumentVersionWithoutContent;

View file

@ -1,4 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // 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"; import type { EventRecord } from "./EventRecord";
export type EventBatch = { headEventId: number, events: Array<EventRecord>, }; export type EventBatch = { headEventId: number,
/**
* Last event in this page; `head_event_id` is the vault's current head.
*/
endEventId?: number, events: Array<EventRecord>, };

View file

@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // 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, };

View file

@ -1,5 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. // 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 { 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;

View file

@ -123,5 +123,11 @@ pub struct VaultSnapshot {
pub struct EventBatch { pub struct EventBatch {
#[ts(as = "f64")] #[ts(as = "f64")]
pub head_event_id: VaultUpdateId, 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<f64>")]
pub end_event_id: Option<VaultUpdateId>,
pub events: Vec<EventRecord>, pub events: Vec<EventRecord>,
} }

View file

@ -1,16 +1,13 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use ts_rs::TS; 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)] #[derive(TS, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct WebSocketHandshake { pub struct WebSocketHandshake {
pub token: String, pub token: String,
pub device_id: DeviceId, pub device_id: DeviceId,
#[ts(as = "Option<i32>")]
pub last_seen_vault_update_id: Option<VaultUpdateId>,
} }
#[derive(TS, Deserialize, Clone, Debug)] #[derive(TS, Deserialize, Clone, Debug)]
@ -67,6 +64,6 @@ pub enum WebSocketClientMessage {
#[serde(rename_all = "camelCase", tag = "type")] #[serde(rename_all = "camelCase", tag = "type")]
#[ts(export)] #[ts(export)]
pub enum WebSocketServerMessage { pub enum WebSocketServerMessage {
VaultEvents(EventBatch), VaultChanged,
CursorPositions(CursorPositionFromServer), CursorPositions(CursorPositionFromServer),
} }

View file

@ -2,7 +2,7 @@ use serde::{self, Deserialize, Serialize};
use ts_rs::TS; use ts_rs::TS;
use crate::app_state::database::models::{ use crate::app_state::database::models::{
DocumentVersion, DocumentVersionWithoutContent, FileManifest, VaultUpdateId, DocumentVersionWithoutContent, FileManifest, VaultUpdateId,
}; };
/// Response to a ping request. /// Response to a ping request.
@ -34,7 +34,7 @@ pub enum DocumentUpdateResponse {
Accepted(DocumentVersionWithoutContent), Accepted(DocumentVersionWithoutContent),
/// Nothing was written. The client must incorporate this version before retrying. /// Nothing was written. The client must incorporate this version before retrying.
StaleBase(DocumentVersion), StaleBase(DocumentVersionWithoutContent),
} }
#[derive(TS, Debug, Clone, Serialize, Deserialize)] #[derive(TS, Debug, Clone, Serialize, Deserialize)]