Working for non-deletes

This commit is contained in:
Andras Schmelczer 2025-03-09 09:07:18 +00:00
parent ec54d0fdb3
commit 054d109ef8
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
12 changed files with 574 additions and 603 deletions

View file

@ -0,0 +1,15 @@
export function createPromise<T = void>(): [
Promise<T>,
(value: T) => void,
(error: unknown) => void
] {
let resolve: undefined | ((resolved: T) => void) = undefined;
let reject: undefined | ((error: unknown) => void) = undefined;
const creationPromise = new Promise<T>(
(resolve_, reject_) => ((resolve = resolve_), (reject = reject_))
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return [creationPromise, resolve!, reject!];
}

View file

@ -1,14 +1,14 @@
import type { DocumentMetadata, RelativePath } from "../persistence/database";
import type { DocumentRecord } from "../persistence/database";
import { EMPTY_HASH } from "./hash";
// TODO: make this smarter so that offline files can be renamed & edited at the same time
export function findMatchingFile(
contentHash: string,
candidates: [RelativePath, DocumentMetadata][]
): [RelativePath, DocumentMetadata] | undefined {
candidates: DocumentRecord[]
): DocumentRecord | undefined {
if (contentHash === EMPTY_HASH) {
return undefined;
}
return candidates.find(([_, metadata]) => metadata.hash === contentHash);
return candidates.find(({ metadata }) => metadata?.hash === contentHash);
}