Lint & format
This commit is contained in:
parent
79eb4f6c7b
commit
ba90fc0b41
5 changed files with 41 additions and 25 deletions
|
|
@ -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)"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export class ConnectionStatus {
|
|||
private canFetch = true;
|
||||
private until: Promise<symbol>;
|
||||
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<Response> => {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue