From 83823b48f2fc2b390d03f19ec40ccad99ba06873 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 8 Jun 2025 12:13:35 +0100 Subject: [PATCH] Format and lint --- .../obsidian-plugin/src/vault-link-plugin.ts | 10 +++-- .../cursors/local-cursor-update-listener.ts | 37 ++++++++++--------- .../views/cursors/remote-cursors-plugin.ts | 21 +++++++---- .../src/services/types/ClientCursors.ts | 6 ++- .../services/types/CreateDocumentVersion.ts | 19 ++++++---- .../types/CursorPositionFromClient.ts | 4 +- .../types/CursorPositionFromServer.ts | 4 +- .../src/services/types/CursorSpan.ts | 5 ++- .../services/types/DeleteDocumentVersion.ts | 4 +- .../services/types/DocumentUpdateResponse.ts | 4 +- .../src/services/types/DocumentVersion.ts | 11 +++++- .../types/DocumentVersionWithoutContent.ts | 11 +++++- .../types/FetchLatestDocumentsResponse.ts | 12 +++--- .../src/services/types/PingResponse.ts | 21 ++++++----- .../src/services/types/SerializedError.ts | 6 ++- .../services/types/UpdateDocumentVersion.ts | 6 ++- .../services/types/WebSocketClientMessage.ts | 4 +- .../src/services/types/WebSocketHandshake.ts | 6 ++- .../services/types/WebSocketServerMessage.ts | 4 +- .../services/types/WebSocketVaultUpdate.ts | 5 ++- frontend/sync-client/src/sync-client.ts | 4 +- 21 files changed, 137 insertions(+), 67 deletions(-) diff --git a/frontend/obsidian-plugin/src/vault-link-plugin.ts b/frontend/obsidian-plugin/src/vault-link-plugin.ts index 9b9d62ab..315e2d19 100644 --- a/frontend/obsidian-plugin/src/vault-link-plugin.ts +++ b/frontend/obsidian-plugin/src/vault-link-plugin.ts @@ -6,7 +6,7 @@ import type { Workspace, WorkspaceLeaf } from "obsidian"; -import { MarkdownView } from "obsidian"; +import type { MarkdownView } from "obsidian"; import { Platform, Plugin, TFile } from "obsidian"; import "../manifest.json"; import { HistoryView } from "./views/history/history-view"; @@ -91,7 +91,9 @@ export default class VaultLinkPlugin extends Plugin { this.client, this.app.workspace ); - this.disposables.push(() => cursorListener.dispose()); + this.disposables.push(() => { + cursorListener.dispose(); + }); this.app.workspace.updateOptions(); @@ -195,7 +197,9 @@ export default class VaultLinkPlugin extends Plugin { } } ) - ].forEach((event) => this.registerEvent(event)); + ].forEach((event) => { + this.registerEvent(event); + }); } private async rateLimitedUpdate(path: string): Promise { diff --git a/frontend/obsidian-plugin/src/views/cursors/local-cursor-update-listener.ts b/frontend/obsidian-plugin/src/views/cursors/local-cursor-update-listener.ts index 319ae285..99a9828d 100644 --- a/frontend/obsidian-plugin/src/views/cursors/local-cursor-update-listener.ts +++ b/frontend/obsidian-plugin/src/views/cursors/local-cursor-update-listener.ts @@ -1,12 +1,8 @@ -import { - EventRef, - Workspace, - Editor, - MarkdownView, - MarkdownFileInfo -} from "obsidian"; -import { SyncClient } from "sync-client"; -import { Cursor, getCursorsFromEditor } from "./get-cursors-from-editor"; +import type { Workspace } from "obsidian"; +import { EventRef, Editor, MarkdownView, MarkdownFileInfo } from "obsidian"; +import type { Logger, SyncClient } from "sync-client"; +import type { Cursor } from "./get-cursors-from-editor"; +import { getCursorsFromEditor } from "./get-cursors-from-editor"; export class LocalCursorUpdateListener { private static readonly UPDATE_INTERVAL_MS = 50; @@ -17,10 +13,13 @@ export class LocalCursorUpdateListener { private readonly client: SyncClient, private readonly workspace: Workspace ) { - this.eventHandle = setInterval( - () => this.updateAllCursors(), - LocalCursorUpdateListener.UPDATE_INTERVAL_MS - ); + this.eventHandle = setInterval(() => { + this.updateAllCursors(); + }, LocalCursorUpdateListener.UPDATE_INTERVAL_MS); + } + + public dispose(): void { + clearInterval(this.eventHandle); } private updateAllCursors(): void { @@ -32,7 +31,13 @@ export class LocalCursorUpdateListener { return; } this.lastCursorState = currentCursors; - this.client.updateLocalCursors(currentCursors); + this.client + .updateLocalCursors(currentCursors) + .catch((error: unknown) => { + this.client.logger.error( + `Failed to update local cursors: ${error}` + ); + }); } private getAllCursors(): Record { @@ -50,8 +55,4 @@ export class LocalCursorUpdateListener { }); return cursors; } - - public dispose(): void { - clearInterval(this.eventHandle); - } } diff --git a/frontend/obsidian-plugin/src/views/cursors/remote-cursors-plugin.ts b/frontend/obsidian-plugin/src/views/cursors/remote-cursors-plugin.ts index 2142fdff..e7797d1a 100644 --- a/frontend/obsidian-plugin/src/views/cursors/remote-cursors-plugin.ts +++ b/frontend/obsidian-plugin/src/views/cursors/remote-cursors-plugin.ts @@ -103,15 +103,19 @@ export const remoteCursorsPlugin = ViewPlugin.fromClass( } ); -export function setCursors(clients: ClientCursors[], app: App) { +export function setCursors(clients: ClientCursors[], app: App): void { cursors = clients.flatMap((client) => { - return Object.keys(client.cursors).flatMap((path) => - client.cursors[path]!.map((span) => ({ - name: client.userName, - path, - span - })) - ); + const clientCursors = client.cursors; + return Object.keys(clientCursors).flatMap((path) => { + const spans = clientCursors[path]; + return spans + ? spans.map((span) => ({ + name: client.userName, + path, + span + })) + : []; + }); }); app.workspace @@ -120,6 +124,7 @@ export function setCursors(clients: ClientCursors[], app: App) { .filter((view) => view instanceof MarkdownView) .forEach((view) => { // @ts-expect-error, not typed + // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion const editor = view.editor.cm as EditorView; editor.dispatch({ diff --git a/frontend/sync-client/src/services/types/ClientCursors.ts b/frontend/sync-client/src/services/types/ClientCursors.ts index cec4f064..9bf8739f 100644 --- a/frontend/sync-client/src/services/types/ClientCursors.ts +++ b/frontend/sync-client/src/services/types/ClientCursors.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 { CursorSpan } from "./CursorSpan"; -export interface ClientCursors { userName: string, deviceId: string, cursors: Partial>, } +export interface ClientCursors { + userName: string; + deviceId: string; + cursors: Partial>; +} diff --git a/frontend/sync-client/src/services/types/CreateDocumentVersion.ts b/frontend/sync-client/src/services/types/CreateDocumentVersion.ts index 2a5ea1a0..d4bd376b 100644 --- a/frontend/sync-client/src/services/types/CreateDocumentVersion.ts +++ b/frontend/sync-client/src/services/types/CreateDocumentVersion.ts @@ -1,10 +1,13 @@ // 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[], } +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/CursorPositionFromClient.ts b/frontend/sync-client/src/services/types/CursorPositionFromClient.ts index f51b6603..d33c0c8e 100644 --- a/frontend/sync-client/src/services/types/CursorPositionFromClient.ts +++ b/frontend/sync-client/src/services/types/CursorPositionFromClient.ts @@ -1,4 +1,6 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { CursorSpan } from "./CursorSpan"; -export interface CursorPositionFromClient { documentToCursors: Partial>, } +export interface CursorPositionFromClient { + documentToCursors: Partial>; +} diff --git a/frontend/sync-client/src/services/types/CursorPositionFromServer.ts b/frontend/sync-client/src/services/types/CursorPositionFromServer.ts index ed6ac7b2..2556b748 100644 --- a/frontend/sync-client/src/services/types/CursorPositionFromServer.ts +++ b/frontend/sync-client/src/services/types/CursorPositionFromServer.ts @@ -1,4 +1,6 @@ // 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 7424067c..5bc2542e 100644 --- a/frontend/sync-client/src/services/types/CursorSpan.ts +++ b/frontend/sync-client/src/services/types/CursorSpan.ts @@ -1,3 +1,6 @@ // 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/DeleteDocumentVersion.ts b/frontend/sync-client/src/services/types/DeleteDocumentVersion.ts index 5d4bad98..9edb09ed 100644 --- a/frontend/sync-client/src/services/types/DeleteDocumentVersion.ts +++ b/frontend/sync-client/src/services/types/DeleteDocumentVersion.ts @@ -1,3 +1,5 @@ // 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 DeleteDocumentVersion { + relativePath: string; +} diff --git a/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts b/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts index 418117e6..f0ed7abf 100644 --- a/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts +++ b/frontend/sync-client/src/services/types/DocumentUpdateResponse.ts @@ -5,4 +5,6 @@ import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutCont /** * Response to an update document request. */ -export type DocumentUpdateResponse = { "type": "FastForwardUpdate" } & DocumentVersionWithoutContent | { "type": "MergingUpdate" } & DocumentVersion; +export type DocumentUpdateResponse = + | ({ type: "FastForwardUpdate" } & DocumentVersionWithoutContent) + | ({ type: "MergingUpdate" } & DocumentVersion); diff --git a/frontend/sync-client/src/services/types/DocumentVersion.ts b/frontend/sync-client/src/services/types/DocumentVersion.ts index 3d50ae65..2076d296 100644 --- a/frontend/sync-client/src/services/types/DocumentVersion.ts +++ b/frontend/sync-client/src/services/types/DocumentVersion.ts @@ -1,3 +1,12 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface DocumentVersion { vaultUpdateId: number, documentId: string, relativePath: string, updatedDate: string, contentBase64: string, isDeleted: boolean, userId: string, deviceId: string, } +export interface DocumentVersion { + vaultUpdateId: number; + documentId: string; + relativePath: string; + updatedDate: string; + contentBase64: string; + isDeleted: boolean; + userId: string; + deviceId: string; +} diff --git a/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts b/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts index af064db8..cb23f6a5 100644 --- a/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts +++ b/frontend/sync-client/src/services/types/DocumentVersionWithoutContent.ts @@ -1,3 +1,12 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface DocumentVersionWithoutContent { vaultUpdateId: number, documentId: string, relativePath: string, updatedDate: string, isDeleted: boolean, userId: string, deviceId: string, contentSize: number, } +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/FetchLatestDocumentsResponse.ts b/frontend/sync-client/src/services/types/FetchLatestDocumentsResponse.ts index 3be625bd..67c19b2d 100644 --- a/frontend/sync-client/src/services/types/FetchLatestDocumentsResponse.ts +++ b/frontend/sync-client/src/services/types/FetchLatestDocumentsResponse.ts @@ -4,8 +4,10 @@ import type { DocumentVersionWithoutContent } from "./DocumentVersionWithoutCont /** * Response to a fetch latest documents request. */ -export interface FetchLatestDocumentsResponse { latestDocuments: DocumentVersionWithoutContent[], -/** - * The update ID of the latest document in the response. - */ -lastUpdateId: bigint, } +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/PingResponse.ts b/frontend/sync-client/src/services/types/PingResponse.ts index 7d64ea36..b0d993f2 100644 --- a/frontend/sync-client/src/services/types/PingResponse.ts +++ b/frontend/sync-client/src/services/types/PingResponse.ts @@ -3,13 +3,14 @@ /** * Response to a ping request. */ -export interface PingResponse { -/** - * Semantic version of the server. - */ -serverVersion: string, -/** - * Whether the client is authenticated based on the sent Authorization - * header. - */ -isAuthenticated: boolean, } +export interface PingResponse { + /** + * Semantic version of the server. + */ + serverVersion: string; + /** + * Whether the client is authenticated based on the sent Authorization + * header. + */ + isAuthenticated: boolean; +} diff --git a/frontend/sync-client/src/services/types/SerializedError.ts b/frontend/sync-client/src/services/types/SerializedError.ts index 4389289e..c0979c5a 100644 --- a/frontend/sync-client/src/services/types/SerializedError.ts +++ b/frontend/sync-client/src/services/types/SerializedError.ts @@ -1,3 +1,7 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface SerializedError { errorType: string, message: string, causes: string[], } +export interface SerializedError { + errorType: string; + message: string; + causes: string[]; +} diff --git a/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts b/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts index e0ddd5ac..bc3d54e5 100644 --- a/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts +++ b/frontend/sync-client/src/services/types/UpdateDocumentVersion.ts @@ -1,3 +1,7 @@ // 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[], } +export interface UpdateDocumentVersion { + parent_version_id: bigint; + relative_path: string; + content: number[]; +} diff --git a/frontend/sync-client/src/services/types/WebSocketClientMessage.ts b/frontend/sync-client/src/services/types/WebSocketClientMessage.ts index 5765a0d0..e7de2cf3 100644 --- a/frontend/sync-client/src/services/types/WebSocketClientMessage.ts +++ b/frontend/sync-client/src/services/types/WebSocketClientMessage.ts @@ -2,4 +2,6 @@ import type { CursorPositionFromClient } from "./CursorPositionFromClient"; import type { WebSocketHandshake } from "./WebSocketHandshake"; -export type WebSocketClientMessage = { "type": "handshake" } & WebSocketHandshake | { "type": "cursorPositions" } & CursorPositionFromClient; +export type WebSocketClientMessage = + | ({ type: "handshake" } & WebSocketHandshake) + | ({ type: "cursorPositions" } & CursorPositionFromClient); diff --git a/frontend/sync-client/src/services/types/WebSocketHandshake.ts b/frontend/sync-client/src/services/types/WebSocketHandshake.ts index d25651f9..068b3505 100644 --- a/frontend/sync-client/src/services/types/WebSocketHandshake.ts +++ b/frontend/sync-client/src/services/types/WebSocketHandshake.ts @@ -1,3 +1,7 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export interface WebSocketHandshake { token: string, deviceId: string, lastSeenVaultUpdateId: number | null, } +export interface WebSocketHandshake { + token: string; + deviceId: string; + lastSeenVaultUpdateId: number | null; +} diff --git a/frontend/sync-client/src/services/types/WebSocketServerMessage.ts b/frontend/sync-client/src/services/types/WebSocketServerMessage.ts index 45e37358..8ebf8911 100644 --- a/frontend/sync-client/src/services/types/WebSocketServerMessage.ts +++ b/frontend/sync-client/src/services/types/WebSocketServerMessage.ts @@ -2,4 +2,6 @@ import type { CursorPositionFromServer } from "./CursorPositionFromServer"; import type { WebSocketVaultUpdate } from "./WebSocketVaultUpdate"; -export type WebSocketServerMessage = { "type": "vaultUpdate" } & WebSocketVaultUpdate | { "type": "cursorPositions" } & CursorPositionFromServer; +export type WebSocketServerMessage = + | ({ type: "vaultUpdate" } & WebSocketVaultUpdate) + | ({ type: "cursorPositions" } & CursorPositionFromServer); diff --git a/frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts b/frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts index 39e03b6f..ad50c25d 100644 --- a/frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts +++ b/frontend/sync-client/src/services/types/WebSocketVaultUpdate.ts @@ -1,4 +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"; -export interface WebSocketVaultUpdate { documents: DocumentVersionWithoutContent[], isInitialSync: boolean, } +export interface WebSocketVaultUpdate { + documents: DocumentVersionWithoutContent[]; + isInitialSync: boolean; +} diff --git a/frontend/sync-client/src/sync-client.ts b/frontend/sync-client/src/sync-client.ts index 70e100ed..6d51212e 100644 --- a/frontend/sync-client/src/sync-client.ts +++ b/frontend/sync-client/src/sync-client.ts @@ -275,7 +275,9 @@ export class SyncClient { }); } - public async updateLocalCursors(documentToCursors: Record): Promise { + public async updateLocalCursors( + documentToCursors: Record + ): Promise { this.webSocketManager.updateLocalCursors({ documentToCursors }); }