diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..5b0ee4b0 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[env] +TS_RS_EXPORT_DIR = { value = "frontend/sync-client/src/services/types", relative = true } diff --git a/.gitignore b/.gitignore index 967b2b65..ab97af82 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ frontend/*/dist # Rust build folders sync-server/target sync-server/artifacts -sync-server/bindings/*.ts # build folders sync-server/db.sqlite3* diff --git a/frontend/sync-client/src/services/types/CreateDocumentVersion.ts b/frontend/sync-client/src/services/types/CreateDocumentVersion.ts deleted file mode 100644 index ed921f18..00000000 --- a/frontend/sync-client/src/services/types/CreateDocumentVersion.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export interface CreateDocumentVersion { - /** - * The client can decide the document id (if it wishes to) in order - * to help with syncing. If the client does not provide a document id, - * the server will generate one. If the client provides a document id - * it must not already exist in the database. - */ - document_id: string | null; - relative_path: string; - content: number[]; -} diff --git a/frontend/sync-client/src/services/types/CursorPositionFromServer.ts b/frontend/sync-client/src/services/types/CursorPositionFromServer.ts index 52a24f27..d9be7d82 100644 --- a/frontend/sync-client/src/services/types/CursorPositionFromServer.ts +++ b/frontend/sync-client/src/services/types/CursorPositionFromServer.ts @@ -1,6 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { ClientCursors } from "./ClientCursors"; -export interface CursorPositionFromServer { - clients: ClientCursors[]; -} +export interface CursorPositionFromServer { clients: ClientCursors[] } diff --git a/frontend/sync-client/src/services/types/CursorSpan.ts b/frontend/sync-client/src/services/types/CursorSpan.ts index 2cc2b7fc..d2fc9614 100644 --- a/frontend/sync-client/src/services/types/CursorSpan.ts +++ b/frontend/sync-client/src/services/types/CursorSpan.ts @@ -1,6 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface CursorSpan { - start: number; - end: number; -} +export interface CursorSpan { start: number; end: number } diff --git a/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts b/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts index 7fd06c7a..29f23cfb 100644 --- a/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts +++ b/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts @@ -6,5 +6,5 @@ import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutCont * Response to an update document request. */ export type DocumentUpdateResponse = - | ({ type: "FastForwardUpdate" } & DocumentVersionWithoutContent) - | ({ type: "MergingUpdate" } & DocumentVersion); + | ({ type: "Accepted" } & DocumentVersionWithoutContent) + | ({ type: "StaleBase" } & DocumentVersion); diff --git a/frontend/sync-client/src/services/types/DocumentVersion.ts b/frontend/sync-client/src/services/types/DocumentVersion.ts index 3b9aa37b..a636e4fb 100644 --- a/frontend/sync-client/src/services/types/DocumentVersion.ts +++ b/frontend/sync-client/src/services/types/DocumentVersion.ts @@ -1,12 +1,11 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. export interface DocumentVersion { + contentBase64: string; vaultUpdateId: number; documentId: string; - relativePath: string; updatedDate: string; - contentBase64: string; - isDeleted: boolean; userId: string; deviceId: string; + contentSize: number; } diff --git a/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts b/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts index 4b24e7c5..d4e8165a 100644 --- a/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts +++ b/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts @@ -3,9 +3,7 @@ export interface DocumentVersionWithoutContent { vaultUpdateId: number; documentId: string; - relativePath: string; updatedDate: string; - isDeleted: boolean; userId: string; deviceId: string; contentSize: number; diff --git a/frontend/sync-client/src/services/types/EventBatch.ts b/frontend/sync-client/src/services/types/EventBatch.ts new file mode 100644 index 00000000..11412274 --- /dev/null +++ b/frontend/sync-client/src/services/types/EventBatch.ts @@ -0,0 +1,4 @@ +// 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 interface EventBatch { headEventId: number; events: EventRecord[] } diff --git a/frontend/sync-client/src/services/types/EventRecord.ts b/frontend/sync-client/src/services/types/EventRecord.ts new file mode 100644 index 00000000..2e50d69a --- /dev/null +++ b/frontend/sync-client/src/services/types/EventRecord.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutContent"; +import type { Manifest } from "./Manifest"; + +export type EventRecord = { eventId: number; requestId: string } & ( + | { type: "content"; document: DocumentVersionWithoutContent } + | { type: "manifest"; manifest: Manifest } +); diff --git a/frontend/sync-client/src/services/types/FetchLatestDocumentsResponse.ts b/frontend/sync-client/src/services/types/FetchLatestDocumentsResponse.ts deleted file mode 100644 index 160c9279..00000000 --- a/frontend/sync-client/src/services/types/FetchLatestDocumentsResponse.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutContent"; - -/** - * Response to a fetch latest documents request. - */ -export interface FetchLatestDocumentsResponse { - latestDocuments: DocumentVersionWithoutContent[]; - /** - * The update ID of the latest document in the response. - */ - lastUpdateId: bigint; -} diff --git a/frontend/sync-client/src/services/types/DeleteDocumentVersion.ts b/frontend/sync-client/src/services/types/Manifest.ts similarity index 57% rename from frontend/sync-client/src/services/types/DeleteDocumentVersion.ts rename to frontend/sync-client/src/services/types/Manifest.ts index 99ecc9e7..f32ce231 100644 --- a/frontend/sync-client/src/services/types/DeleteDocumentVersion.ts +++ b/frontend/sync-client/src/services/types/Manifest.ts @@ -1,5 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface DeleteDocumentVersion { - relativePath: string; -} +export interface Manifest { manifestId: number; entries: Record } diff --git a/frontend/sync-client/src/services/types/ManifestUpdateResponse.ts b/frontend/sync-client/src/services/types/ManifestUpdateResponse.ts new file mode 100644 index 00000000..db3ea4a1 --- /dev/null +++ b/frontend/sync-client/src/services/types/ManifestUpdateResponse.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Manifest } from "./Manifest"; + +export type ManifestUpdateResponse = + | ({ type: "Accepted" } & Manifest) + | ({ type: "StaleBase" } & Manifest); diff --git a/frontend/sync-client/src/services/types/PingResponse.ts b/frontend/sync-client/src/services/types/PingResponse.ts index 6db66354..f96520e9 100644 --- a/frontend/sync-client/src/services/types/PingResponse.ts +++ b/frontend/sync-client/src/services/types/PingResponse.ts @@ -5,21 +5,21 @@ */ export interface PingResponse { /** - * Semantic version of the server. - */ + * Semantic version of the server. + */ serverVersion: string; /** - * Whether the client is authenticated based on the sent Authorization - * header. - */ + * Whether the client is authenticated based on the sent Authorization + * header. + */ isAuthenticated: boolean; /** - * List of file extensions that are allowed to be merged. - */ + * List of file extensions that are allowed to be merged. + */ mergeableFileExtensions: string[]; /** - * API version ensuring backwards & forwards compatibility between the client - * and server. - */ + * API version ensuring backwards & forwards compatibility between the client + * and server. + */ supportedApiVersion: number; } diff --git a/frontend/sync-client/src/services/types/PushContent.ts b/frontend/sync-client/src/services/types/PushContent.ts new file mode 100644 index 00000000..3035b567 --- /dev/null +++ b/frontend/sync-client/src/services/types/PushContent.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type PushContent = + | { type: "Snapshot"; value: string } + | { type: "Diff"; value: (number | string)[] }; diff --git a/frontend/sync-client/src/services/types/PushDocument.ts b/frontend/sync-client/src/services/types/PushDocument.ts new file mode 100644 index 00000000..8410b96e --- /dev/null +++ b/frontend/sync-client/src/services/types/PushDocument.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { PushContent } from "./PushContent"; + +export interface PushDocument { + requestId: string; + parentVersionId: number | null; + content: PushContent; +} diff --git a/frontend/sync-client/src/services/types/PushManifest.ts b/frontend/sync-client/src/services/types/PushManifest.ts new file mode 100644 index 00000000..ee5e68e4 --- /dev/null +++ b/frontend/sync-client/src/services/types/PushManifest.ts @@ -0,0 +1,7 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export interface PushManifest { + requestId: string; + parentManifestId: number; + entries: Record; +} diff --git a/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts b/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts deleted file mode 100644 index 4e57a297..00000000 --- a/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts +++ /dev/null @@ -1,7 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export interface UpdateDocumentVersion { - parent_version_id: bigint; - relative_path: string; - content: number[]; -} diff --git a/frontend/sync-client/src/services/types/UpdateTextDocumentVersion.ts b/frontend/sync-client/src/services/types/UpdateTextDocumentVersion.ts deleted file mode 100644 index 46f36bd0..00000000 --- a/frontend/sync-client/src/services/types/UpdateTextDocumentVersion.ts +++ /dev/null @@ -1,7 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export interface UpdateTextDocumentVersion { - parentVersionId: number; - relativePath: string; - content: (number | string)[]; -} diff --git a/frontend/sync-client/src/services/types/VaultEvent.ts b/frontend/sync-client/src/services/types/VaultEvent.ts new file mode 100644 index 00000000..426efd5b --- /dev/null +++ b/frontend/sync-client/src/services/types/VaultEvent.ts @@ -0,0 +1,7 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutContent"; +import type { Manifest } from "./Manifest"; + +export type VaultEvent = + | { type: "content"; document: DocumentVersionWithoutContent } + | { type: "manifest"; manifest: Manifest }; diff --git a/frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts b/frontend/sync-client/src/services/types/VaultSnapshot.ts similarity index 66% rename from frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts rename to frontend/sync-client/src/services/types/VaultSnapshot.ts index f1ea0f80..3c0ff9a7 100644 --- a/frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts +++ b/frontend/sync-client/src/services/types/VaultSnapshot.ts @@ -1,7 +1,9 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutContent"; +import type { Manifest } from "./Manifest"; -export interface WebSocketVaultUpdate { +export interface VaultSnapshot { + headEventId: number; + manifest: Manifest; documents: DocumentVersionWithoutContent[]; - isInitialSync: boolean; } diff --git a/frontend/sync-client/src/services/types/WebSocketServerMessage.ts b/frontend/sync-client/src/services/types/WebSocketServerMessage.ts index fd250b7b..d1d10a8f 100644 --- a/frontend/sync-client/src/services/types/WebSocketServerMessage.ts +++ b/frontend/sync-client/src/services/types/WebSocketServerMessage.ts @@ -1,7 +1,7 @@ // 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 { WebSocketVaultUpdate } from "./WebSocketVaultUpdate"; +import type { EventBatch } from "./EventBatch"; export type WebSocketServerMessage = - | ({ type: "vaultUpdate" } & WebSocketVaultUpdate) + | ({ type: "vaultEvents" } & EventBatch) | ({ type: "cursorPositions" } & CursorPositionFromServer); diff --git a/scripts/update-api-types.sh b/scripts/update-api-types.sh index 3f4a9e2a..055dd643 100755 --- a/scripts/update-api-types.sh +++ b/scripts/update-api-types.sh @@ -2,21 +2,19 @@ set -e -rm -rf sync-server/bindings - -cd sync-server -cargo test export_bindings -cd - - -# Both target directories contain only generated bindings — wipe and copy +# This directory contains only generated bindings. ts-rs writes here directly, +# as configured in .cargo/config.toml. rm -f frontend/sync-client/src/services/types/*.ts -rm -f frontend/history-ui/src/lib/types/*.ts -cp -r sync-server/bindings/* frontend/sync-client/src/services/types/ -cp -r sync-server/bindings/* frontend/history-ui/src/lib/types/ -cd frontend -npm run lint -cd .. +( + cd sync-server + cargo test export_bindings +) + +( + cd frontend + npm run lint +) # Format all files across the project (frontend and backend) npx -C frontend prettier --write "**/*.{ts,js,json,md,yml,yaml}"