lint
This commit is contained in:
parent
b5260e97e9
commit
9ad54eff7a
21 changed files with 76 additions and 75 deletions
|
|
@ -9,10 +9,7 @@ export class ObsidianFileEventHandler {
|
|||
if (file instanceof TFile) {
|
||||
this.client.logger.info(`File created: ${file.path}`);
|
||||
|
||||
await this.client.syncer.syncLocallyCreatedFile(
|
||||
file.path,
|
||||
new Date(file.stat.ctime)
|
||||
);
|
||||
await this.client.syncer.syncLocallyCreatedFile(file.path);
|
||||
} else {
|
||||
this.client.logger.debug(`Folder created: ${file.path}, ignored`);
|
||||
}
|
||||
|
|
@ -34,8 +31,7 @@ export class ObsidianFileEventHandler {
|
|||
|
||||
await this.client.syncer.syncLocallyUpdatedFile({
|
||||
oldPath,
|
||||
relativePath: file.path,
|
||||
updateTime: new Date(file.stat.ctime)
|
||||
relativePath: file.path
|
||||
});
|
||||
} else {
|
||||
this.client.logger.debug(
|
||||
|
|
@ -53,8 +49,7 @@ export class ObsidianFileEventHandler {
|
|||
this.client.logger.info(`File modified: ${file.path}`);
|
||||
|
||||
await this.client.syncer.syncLocallyUpdatedFile({
|
||||
relativePath: file.path,
|
||||
updateTime: new Date(file.stat.ctime)
|
||||
relativePath: file.path
|
||||
});
|
||||
} else {
|
||||
this.client.logger.debug(`Folder modified: ${file.path}, ignored`);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ export class HistoryView extends ItemView {
|
|||
}
|
||||
|
||||
element.createEl("span", {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
|
||||
text: entry.relativePath
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { WorkspaceLeaf } from "obsidian";
|
||||
import { ItemView } from "obsidian";
|
||||
import type VaultLinkPlugin from "src/vault-link-plugin";
|
||||
import type VaultLinkPlugin from "../vault-link-plugin";
|
||||
import type { SyncClient } from "sync-client";
|
||||
|
||||
export class LogsView extends ItemView {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { App } from "obsidian";
|
||||
import { Notice, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
import type VaultLinkPlugin from "src/vault-link-plugin";
|
||||
import type VaultLinkPlugin from "../vault-link-plugin";
|
||||
import type { StatusDescription } from "./status-description";
|
||||
import { LogsView } from "./logs-view";
|
||||
import { HistoryView } from "./history-view";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { HistoryStats, SyncClient } from "sync-client";
|
||||
import type VaultLinkPlugin from "src/vault-link-plugin";
|
||||
import type VaultLinkPlugin from "../vault-link-plugin";
|
||||
|
||||
export class StatusBar {
|
||||
private readonly statusBarItem: HTMLElement;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import type { Logger } from "../tracing/logger";
|
||||
import type { RelativePath } from "../persistence/database";
|
||||
|
||||
// Manages locks on documents to prevent concurrent modifications
|
||||
// allowing the client's FileOperations implementation to be simpler.
|
||||
// Locks are granted in a first-in-first-out order.
|
||||
export class DocumentLocks {
|
||||
private readonly locked = new Set<RelativePath>();
|
||||
private readonly waiters = new Map<RelativePath, (() => void)[]>();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import type { FileSystemOperations } from "sync-client";
|
||||
import type {
|
||||
Database,
|
||||
DocumentRecord,
|
||||
|
|
@ -7,6 +6,7 @@ import type {
|
|||
import { FileOperations } from "./file-operations";
|
||||
import { Logger } from "../tracing/logger";
|
||||
import { assertSetContainsExactly } from "../utils/assert-set-contains-exactly";
|
||||
import type { FileSystemOperations } from "./filesystem-operations";
|
||||
|
||||
describe("File operations", () => {
|
||||
class MockDatabase {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { Logger } from "src/tracing/logger";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
import type { FileSystemOperations } from "./filesystem-operations";
|
||||
import type { Database, RelativePath } from "src/persistence/database";
|
||||
import type { Database, RelativePath } from "../persistence/database";
|
||||
import { isBinary, isFileTypeMergable, mergeText } from "sync_lib";
|
||||
import {
|
||||
FileNotFoundError,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { RelativePath } from "src/persistence/database";
|
||||
import type { RelativePath } from "../persistence/database";
|
||||
|
||||
export interface FileSystemOperations {
|
||||
listAllFiles: () => Promise<RelativePath[]>;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ export class FileNotFoundError extends Error {
|
|||
|
||||
// Decorate FileSystemOperations replacing errors with FileNotFoundError
|
||||
// if the accessed file doesn't exist. It also ensures that there's only
|
||||
// ever a single request in-flight for any one file.
|
||||
// ever a single request in-flight for any one file through the use of
|
||||
// DocumentLocks.
|
||||
export class SafeFileSystemOperations implements FileSystemOperations {
|
||||
private readonly locks: DocumentLocks;
|
||||
|
||||
|
|
@ -24,7 +25,6 @@ export class SafeFileSystemOperations implements FileSystemOperations {
|
|||
}
|
||||
|
||||
public async listAllFiles(): Promise<RelativePath[]> {
|
||||
this.logger.debug("Listing all files");
|
||||
return this.fs.listAllFiles();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ export class Database {
|
|||
relativePath: RelativePath,
|
||||
promise: Promise<void>
|
||||
): Promise<void> {
|
||||
let entry = this.getLatestDocumentByRelativePath(relativePath);
|
||||
const entry = this.getLatestDocumentByRelativePath(relativePath);
|
||||
|
||||
if (entry === undefined) {
|
||||
throw new Error(
|
||||
|
|
@ -238,7 +238,7 @@ export class Database {
|
|||
relativePath: RelativePath,
|
||||
promise: Promise<void>
|
||||
): void {
|
||||
let previousEntry = this.getLatestDocumentByRelativePath(relativePath);
|
||||
const previousEntry = this.getLatestDocumentByRelativePath(relativePath);
|
||||
|
||||
const entry = {
|
||||
relativePath,
|
||||
|
|
@ -300,7 +300,7 @@ export class Database {
|
|||
({ identity }) => identity !== oldDocument.identity
|
||||
);
|
||||
|
||||
let newDocument = this.getLatestDocumentByRelativePath(newRelativePath);
|
||||
const newDocument = this.getLatestDocumentByRelativePath(newRelativePath);
|
||||
if (newDocument !== undefined && !newDocument.isDeleted) {
|
||||
throw new Error(
|
||||
`Document already exists at new location: ${newRelativePath}`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { Logger } from "src/tracing/logger";
|
||||
import { LogLevel } from "src/tracing/logger";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
import { LogLevel } from "../tracing/logger";
|
||||
|
||||
export interface SyncSettings {
|
||||
remoteUri: string;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Settings } from "../persistence/settings";
|
||||
import { Logger } from "../tracing/logger";
|
||||
import type { Settings } from "../persistence/settings";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
import { createPromise } from "../utils/create-promise";
|
||||
import { retriedFetchFactory } from "../utils/retried-fetch";
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import type {
|
|||
} from "../persistence/database";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
import type { Settings } from "../persistence/settings";
|
||||
import { ConnectedState } from "./connected-state";
|
||||
import type { ConnectedState } from "./connected-state";
|
||||
|
||||
export interface CheckConnectionResult {
|
||||
isSuccessful: boolean;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import type { Database, RelativePath } from "../persistence/database";
|
||||
import type { SyncService } from "src/services/sync-service";
|
||||
import type { Logger } from "src/tracing/logger";
|
||||
import type { SyncHistory } from "src/tracing/sync-history";
|
||||
import type { SyncService } from "../services/sync-service";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
import type { SyncHistory } from "../tracing/sync-history";
|
||||
import PQueue from "p-queue";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { hash } from "src/utils/hash";
|
||||
import type { components } from "src/services/types";
|
||||
import type { Settings } from "src/persistence/settings";
|
||||
import type { FileOperations } from "src/file-operations/file-operations";
|
||||
import { findMatchingFile } from "src/utils/find-matching-file";
|
||||
import { hash } from "../utils/hash";
|
||||
import type { components } from "../services/types";
|
||||
import type { Settings } from "../persistence/settings";
|
||||
import type { FileOperations } from "../file-operations/file-operations";
|
||||
import { findMatchingFile } from "../utils/find-matching-file";
|
||||
import { UnrestrictedSyncer } from "./unrestricted-syncer";
|
||||
import { FileNotFoundError } from "src/file-operations/safe-filesystem-operations";
|
||||
import { createPromise } from "src/utils/create-promise";
|
||||
import { FileNotFoundError } from "../file-operations/safe-filesystem-operations";
|
||||
import { createPromise } from "../utils/create-promise";
|
||||
|
||||
export class Syncer {
|
||||
private readonly remainingOperationsListeners: ((
|
||||
|
|
@ -45,9 +45,9 @@ export class Syncer {
|
|||
});
|
||||
|
||||
this.syncQueue.on("active", () =>
|
||||
this.remainingOperationsListeners.forEach((listener) =>
|
||||
listener(this.syncQueue.size)
|
||||
)
|
||||
{ this.remainingOperationsListeners.forEach((listener) =>
|
||||
{ listener(this.syncQueue.size); }
|
||||
); }
|
||||
);
|
||||
|
||||
this.internalSyncer = new UnrestrictedSyncer(
|
||||
|
|
@ -107,7 +107,7 @@ export class Syncer {
|
|||
);
|
||||
|
||||
try {
|
||||
await this.syncQueue.add(() =>
|
||||
await this.syncQueue.add(async () =>
|
||||
this.internalSyncer.unrestrictedSyncLocallyCreatedFile(
|
||||
proposedDocumentId,
|
||||
() => this.database.getDocumentByUpdatePromise(promise)
|
||||
|
|
@ -261,7 +261,7 @@ export class Syncer {
|
|||
public async reset(): Promise<void> {
|
||||
this.syncQueue.clear();
|
||||
await this.syncQueue.onEmpty();
|
||||
this.remainingOperationsListeners.forEach((listener) => listener(0));
|
||||
this.remainingOperationsListeners.forEach((listener) => { listener(0); });
|
||||
this.internalSyncer.reset();
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +297,7 @@ export class Syncer {
|
|||
private async syncRemotelyUpdatedFile(
|
||||
remoteVersion: components["schemas"]["DocumentVersionWithoutContent"]
|
||||
): Promise<void> {
|
||||
let document = this.database.getDocumentByDocumentId(
|
||||
const document = this.database.getDocumentByDocumentId(
|
||||
remoteVersion.documentId
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,18 +5,18 @@ import type {
|
|||
RelativePath
|
||||
} from "../persistence/database";
|
||||
|
||||
import type { SyncService } from "src/services/sync-service";
|
||||
import { Logger } from "src/tracing/logger";
|
||||
import type { SyncHistory } from "src/tracing/sync-history";
|
||||
import { SyncSource, SyncStatus, SyncType } from "src/tracing/sync-history";
|
||||
import { EMPTY_HASH, hash } from "src/utils/hash";
|
||||
import type { components } from "src/services/types";
|
||||
import { deserialize } from "src/utils/deserialize";
|
||||
import type { Settings } from "src/persistence/settings";
|
||||
import type { FileOperations } from "src/file-operations/file-operations";
|
||||
import { FileNotFoundError } from "src/file-operations/safe-filesystem-operations";
|
||||
import type { SyncService } from "../services/sync-service";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
import type { SyncHistory } from "../tracing/sync-history";
|
||||
import { SyncSource, SyncStatus, SyncType } from "../tracing/sync-history";
|
||||
import { EMPTY_HASH, hash } from "../utils/hash";
|
||||
import type { components } from "../services/types";
|
||||
import { deserialize } from "../utils/deserialize";
|
||||
import type { Settings } from "../persistence/settings";
|
||||
import type { FileOperations } from "../file-operations/file-operations";
|
||||
import { FileNotFoundError } from "../file-operations/safe-filesystem-operations";
|
||||
import { DocumentLocks } from "../file-operations/document-locks";
|
||||
import { createPromise } from "src/utils/create-promise";
|
||||
import { createPromise } from "../utils/create-promise";
|
||||
|
||||
export class UnrestrictedSyncer {
|
||||
private readonly locks: DocumentLocks;
|
||||
|
|
@ -289,7 +289,6 @@ export class UnrestrictedSyncer {
|
|||
let localMetadata = getLatestDocument();
|
||||
|
||||
if (
|
||||
localMetadata !== undefined &&
|
||||
localMetadata?.metadata !== undefined
|
||||
) {
|
||||
// If the file exists locally, let's pretend the user has updated it
|
||||
|
|
@ -352,11 +351,11 @@ export class UnrestrictedSyncer {
|
|||
remoteVersion.relativePath,
|
||||
contentBytes,
|
||||
() =>
|
||||
this.database.getNewResolvedDocumentByRelativePath(
|
||||
{ this.database.getNewResolvedDocumentByRelativePath(
|
||||
remoteVersion.documentId,
|
||||
remoteVersion.relativePath,
|
||||
promise
|
||||
)
|
||||
); }
|
||||
);
|
||||
|
||||
const document =
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { RelativePath } from "src/persistence/database";
|
||||
import type { RelativePath } from "../persistence/database";
|
||||
import type { Logger } from "./logger";
|
||||
|
||||
export interface CommonHistoryEntry {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as fetchRetryFactory from "fetch-retry";
|
||||
import type { RequestInitRetryParams } from "fetch-retry";
|
||||
import type { Logger } from "src/tracing/logger";
|
||||
import type { Logger } from "../tracing/logger";
|
||||
|
||||
function getUrlFromInput(input: RequestInfo | URL): string {
|
||||
if (input instanceof URL) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"module": "ESNext",
|
||||
"target": "ESNext",
|
||||
"strict": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"lib": ["DOM", "ESNext"]
|
||||
"moduleResolution": "bundler",
|
||||
"lib": [
|
||||
"DOM", // to get "fetch"
|
||||
],
|
||||
"declaration": true,
|
||||
"declarationDir": "./dist/types"
|
||||
},
|
||||
"exclude": ["./dist"]
|
||||
}
|
||||
"exclude": [
|
||||
"./dist"
|
||||
]
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import { assert } from "../utils/assert";
|
||||
import type {
|
||||
RelativePath,
|
||||
FileSystemOperations,
|
||||
SyncSettings
|
||||
import {
|
||||
type RelativePath,
|
||||
type FileSystemOperations,
|
||||
type SyncSettings,
|
||||
SyncClient
|
||||
} from "sync-client";
|
||||
import { SyncClient } from "sync-client";
|
||||
|
||||
export class MockClient implements FileSystemOperations {
|
||||
protected readonly localFiles = new Map<string, Uint8Array>();
|
||||
|
|
@ -24,8 +24,8 @@ export class MockClient implements FileSystemOperations {
|
|||
await Promise.all(
|
||||
Object.keys(this.initialSettings).map(async (key) => {
|
||||
return this.client.settings.setSetting(
|
||||
key as keyof SyncSettings, // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
||||
this.initialSettings[key as keyof SyncSettings] // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
||||
key as keyof SyncSettings,
|
||||
this.initialSettings[key as keyof SyncSettings]!
|
||||
);
|
||||
})
|
||||
);
|
||||
|
|
@ -88,10 +88,10 @@ export class MockClient implements FileSystemOperations {
|
|||
const newParts = newContent.split(" ").map((part) => part.trim());
|
||||
existingParts.forEach((part) =>
|
||||
// all changes should be additive
|
||||
assert(
|
||||
{ assert(
|
||||
newParts.includes(part),
|
||||
`Part ${part} not found in new content`
|
||||
)
|
||||
); }
|
||||
);
|
||||
|
||||
this.client.logger.info(
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ async function runTest({
|
|||
async function runTests(): Promise<void> {
|
||||
const agentCounts = [2, 8];
|
||||
const jitterScaleInSeconds = [0.5, 0, 2];
|
||||
const concurrencies = [1];
|
||||
const concurrencies = [16, 1];
|
||||
const iterations = [50, 200];
|
||||
const doDeletes = [true, false];
|
||||
|
||||
|
|
@ -101,7 +101,7 @@ async function runTests(): Promise<void> {
|
|||
for (const jitter of jitterScaleInSeconds) {
|
||||
for (const iteration of iterations) {
|
||||
for (const deleteFiles of doDeletes) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
await runTest({
|
||||
agentCount,
|
||||
concurrency,
|
||||
|
|
@ -110,7 +110,6 @@ async function runTests(): Promise<void> {
|
|||
jitterScaleInSeconds: jitter
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue