Lint & format

This commit is contained in:
Andras Schmelczer 2025-03-22 12:09:07 +00:00
parent 79eb4f6c7b
commit ba90fc0b41
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
5 changed files with 41 additions and 25 deletions

View file

@ -109,27 +109,36 @@ describe("File operations", () => {
}); });
it("should deconflict renames with file extension", async () => { it("should deconflict renames with file extension", async () => {
const fs = new FakeFileSystemOperations(); const fileSystemOperations = new FakeFileSystemOperations();
const fileOperations = new FileOperations( const fileOperations = new FileOperations(
new Logger(), new Logger(),
new MockDatabase() as Database, // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion 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("b.md", new Uint8Array());
await fileOperations.create("c.md", new Uint8Array()); await fileOperations.create("c.md", new Uint8Array());
await fileOperations.move("c.md", "b.md"); 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.create("d.md", new Uint8Array());
await fileOperations.move("d.md", "b.md"); 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.md", new Uint8Array());
await fileOperations.create("file-23 (1).md", new Uint8Array()); await fileOperations.create("file-23 (1).md", new Uint8Array());
await fileOperations.move("file-23.md", "file-23 (1).md"); await fileOperations.move("file-23.md", "file-23 (1).md");
assertSetContainsExactly( assertSetContainsExactly(
fs.names, fileSystemOperations.names,
"b.md", "b.md",
"b (1).md", "b (1).md",
"b (2).md", "b (2).md",
@ -139,16 +148,20 @@ describe("File operations", () => {
}); });
it("should deconflict renames with paths", async () => { it("should deconflict renames with paths", async () => {
const fs = new FakeFileSystemOperations(); const fileSystemOperations = new FakeFileSystemOperations();
const fileOperations = new FileOperations( const fileOperations = new FileOperations(
new Logger(), new Logger(),
new MockDatabase() as Database, // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion 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/d", new Uint8Array());
await fileOperations.create("a/b.c/e", new Uint8Array()); await fileOperations.create("a/b.c/e", new Uint8Array());
await fileOperations.move("a/b.c/d", "a/b.c/e"); 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)"
);
}); });
}); });

View file

@ -12,7 +12,7 @@ export class FileOperations {
private readonly logger: Logger, private readonly logger: Logger,
private readonly database: Database, private readonly database: Database,
fs: FileSystemOperations, fs: FileSystemOperations,
private readonly nativeLineEndings: string = "\n" private readonly nativeLineEndings = "\n"
) { ) {
this.fs = new SafeFileSystemOperations(fs, logger); this.fs = new SafeFileSystemOperations(fs, logger);
} }

View file

@ -8,7 +8,7 @@ export class ConnectionStatus {
private canFetch = true; private canFetch = true;
private until: Promise<symbol>; private until: Promise<symbol>;
private resolveUntil: (result: symbol) => void; private resolveUntil: (result: symbol) => void;
private rejectUntil: (reason: any) => void; private rejectUntil: (reason: unknown) => void;
public constructor( public constructor(
settings: Settings, 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( public getFetchImplementation(
fetch: typeof globalThis.fetch, fetch: typeof globalThis.fetch,
{ doRetries = true }: { doRetries: boolean } = { doRetries: true } { doRetries = true }: { doRetries: boolean } = { doRetries: true }
@ -34,7 +44,7 @@ export class ConnectionStatus {
return doRetries ? this.retriedFetchFactory(this.logger, fetch) : fetch; return doRetries ? this.retriedFetchFactory(this.logger, fetch) : fetch;
} }
public reset() { public reset(): void {
this.rejectUntil(new Error("Sync was reset")); this.rejectUntil(new Error("Sync was reset"));
[this.until, this.resolveUntil, this.rejectUntil] = createPromise(); [this.until, this.resolveUntil, this.rejectUntil] = createPromise();
} }
@ -42,8 +52,9 @@ export class ConnectionStatus {
private retriedFetchFactory( private retriedFetchFactory(
logger: Logger, logger: Logger,
fetch: typeof globalThis.fetch = globalThis.fetch fetch: typeof globalThis.fetch = globalThis.fetch
) { ): typeof globalThis.fetch {
return async (input: RequestInfo | URL): Promise<Response> => { return async (input: RequestInfo | URL): Promise<Response> => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) { while (true) {
while (!this.canFetch) { while (!this.canFetch) {
await this.until; await this.until;
@ -60,12 +71,12 @@ export class ConnectionStatus {
const fetchPromise = fetch(_input); const fetchPromise = fetch(_input);
// We only want to catch rejections from `this.until` // We only want to catch rejections from `this.until`
let result; let result: symbol | Response | undefined = undefined;
do { do {
result = await Promise.race([this.until, fetchPromise]); result = await Promise.race([this.until, fetchPromise]);
} while (result === ConnectionStatus.UNTIL_RESOLUTION); } 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) { if (!fetchResult.ok) {
this.logger.warn( 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;
}
} }

View file

@ -18,6 +18,7 @@ import { ConnectionStatus } from "./services/connection-status";
export class SyncClient { export class SyncClient {
private remoteListenerIntervalId: NodeJS.Timeout | null = null; private remoteListenerIntervalId: NodeJS.Timeout | null = null;
// eslint-disable-next-line @typescript-eslint/max-params
private constructor( private constructor(
private readonly _history: SyncHistory, private readonly _history: SyncHistory,
private readonly _settings: Settings, private readonly _settings: Settings,

View file

@ -135,7 +135,8 @@ export class UnrestrictedSyncer {
let response: let response:
| components["schemas"]["DocumentVersion"] | components["schemas"]["DocumentVersion"]
| components["schemas"]["DocumentUpdateResponse"]; | components["schemas"]["DocumentUpdateResponse"]
| undefined = undefined;
if ( if (
document.metadata.hash === contentHash && document.metadata.hash === contentHash &&
oldPath === undefined oldPath === undefined