From ba90fc0b41a87384b27c564301ecee767bb12f49 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 22 Mar 2025 12:09:07 +0000 Subject: [PATCH] Lint & format --- .../file-operations/file-operations.test.ts | 29 ++++++++++++----- .../src/file-operations/file-operations.ts | 2 +- .../src/services/connection-status.ts | 31 ++++++++++--------- frontend/sync-client/src/sync-client.ts | 1 + .../sync-operations/unrestricted-syncer.ts | 3 +- 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/frontend/sync-client/src/file-operations/file-operations.test.ts b/frontend/sync-client/src/file-operations/file-operations.test.ts index 0d947e88..4f7dd491 100644 --- a/frontend/sync-client/src/file-operations/file-operations.test.ts +++ b/frontend/sync-client/src/file-operations/file-operations.test.ts @@ -109,27 +109,36 @@ describe("File operations", () => { }); it("should deconflict renames with file extension", async () => { - const fs = new FakeFileSystemOperations(); + const fileSystemOperations = new FakeFileSystemOperations(); const fileOperations = new FileOperations( new Logger(), new MockDatabase() as Database, // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion - fs + fileSystemOperations ); await fileOperations.create("b.md", new Uint8Array()); await fileOperations.create("c.md", new Uint8Array()); await fileOperations.move("c.md", "b.md"); - assertSetContainsExactly(fs.names, "b.md", "b (1).md"); + assertSetContainsExactly( + fileSystemOperations.names, + "b.md", + "b (1).md" + ); await fileOperations.create("d.md", new Uint8Array()); await fileOperations.move("d.md", "b.md"); - assertSetContainsExactly(fs.names, "b.md", "b (1).md", "b (2).md"); + assertSetContainsExactly( + fileSystemOperations.names, + "b.md", + "b (1).md", + "b (2).md" + ); await fileOperations.create("file-23.md", new Uint8Array()); await fileOperations.create("file-23 (1).md", new Uint8Array()); await fileOperations.move("file-23.md", "file-23 (1).md"); assertSetContainsExactly( - fs.names, + fileSystemOperations.names, "b.md", "b (1).md", "b (2).md", @@ -139,16 +148,20 @@ describe("File operations", () => { }); it("should deconflict renames with paths", async () => { - const fs = new FakeFileSystemOperations(); + const fileSystemOperations = new FakeFileSystemOperations(); const fileOperations = new FileOperations( new Logger(), new MockDatabase() as Database, // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion - fs + fileSystemOperations ); await fileOperations.create("a/b.c/d", new Uint8Array()); await fileOperations.create("a/b.c/e", new Uint8Array()); await fileOperations.move("a/b.c/d", "a/b.c/e"); - assertSetContainsExactly(fs.names, "a/b.c/e", "a/b.c/e (1)"); + assertSetContainsExactly( + fileSystemOperations.names, + "a/b.c/e", + "a/b.c/e (1)" + ); }); }); diff --git a/frontend/sync-client/src/file-operations/file-operations.ts b/frontend/sync-client/src/file-operations/file-operations.ts index 6d7b2f81..6cac74f3 100644 --- a/frontend/sync-client/src/file-operations/file-operations.ts +++ b/frontend/sync-client/src/file-operations/file-operations.ts @@ -12,7 +12,7 @@ export class FileOperations { private readonly logger: Logger, private readonly database: Database, fs: FileSystemOperations, - private readonly nativeLineEndings: string = "\n" + private readonly nativeLineEndings = "\n" ) { this.fs = new SafeFileSystemOperations(fs, logger); } diff --git a/frontend/sync-client/src/services/connection-status.ts b/frontend/sync-client/src/services/connection-status.ts index b31d6b95..753af362 100644 --- a/frontend/sync-client/src/services/connection-status.ts +++ b/frontend/sync-client/src/services/connection-status.ts @@ -8,7 +8,7 @@ export class ConnectionStatus { private canFetch = true; private until: Promise; private resolveUntil: (result: symbol) => void; - private rejectUntil: (reason: any) => void; + private rejectUntil: (reason: unknown) => void; public constructor( settings: Settings, @@ -27,6 +27,16 @@ export class ConnectionStatus { }); } + private static getUrlFromInput(input: RequestInfo | URL): string { + if (input instanceof URL) { + return input.href; + } + if (typeof input === "string") { + return input; + } + return input.url; + } + public getFetchImplementation( fetch: typeof globalThis.fetch, { doRetries = true }: { doRetries: boolean } = { doRetries: true } @@ -34,7 +44,7 @@ export class ConnectionStatus { return doRetries ? this.retriedFetchFactory(this.logger, fetch) : fetch; } - public reset() { + public reset(): void { this.rejectUntil(new Error("Sync was reset")); [this.until, this.resolveUntil, this.rejectUntil] = createPromise(); } @@ -42,8 +52,9 @@ export class ConnectionStatus { private retriedFetchFactory( logger: Logger, fetch: typeof globalThis.fetch = globalThis.fetch - ) { + ): typeof globalThis.fetch { return async (input: RequestInfo | URL): Promise => { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition while (true) { while (!this.canFetch) { await this.until; @@ -60,12 +71,12 @@ export class ConnectionStatus { const fetchPromise = fetch(_input); // We only want to catch rejections from `this.until` - let result; + let result: symbol | Response | undefined = undefined; do { result = await Promise.race([this.until, fetchPromise]); } while (result === ConnectionStatus.UNTIL_RESOLUTION); - const fetchResult: Response = result as Response; + const fetchResult: Response = result as Response; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion if (!fetchResult.ok) { this.logger.warn( @@ -88,14 +99,4 @@ export class ConnectionStatus { } }; } - - private static getUrlFromInput(input: RequestInfo | URL): string { - if (input instanceof URL) { - return input.href; - } - if (typeof input === "string") { - return input; - } - return input.url; - } } diff --git a/frontend/sync-client/src/sync-client.ts b/frontend/sync-client/src/sync-client.ts index 86d634ab..8e139f74 100644 --- a/frontend/sync-client/src/sync-client.ts +++ b/frontend/sync-client/src/sync-client.ts @@ -18,6 +18,7 @@ import { ConnectionStatus } from "./services/connection-status"; export class SyncClient { private remoteListenerIntervalId: NodeJS.Timeout | null = null; + // eslint-disable-next-line @typescript-eslint/max-params private constructor( private readonly _history: SyncHistory, private readonly _settings: Settings, diff --git a/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts b/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts index f62f907c..6b233af0 100644 --- a/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts +++ b/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts @@ -135,7 +135,8 @@ export class UnrestrictedSyncer { let response: | components["schemas"]["DocumentVersion"] - | components["schemas"]["DocumentUpdateResponse"]; + | components["schemas"]["DocumentUpdateResponse"] + | undefined = undefined; if ( document.metadata.hash === contentHash && oldPath === undefined