Update types

This commit is contained in:
Andras Schmelczer 2026-09-27 19:34:55 +01:00
commit 4721392281
7 changed files with 45 additions and 18 deletions

View file

@ -21,12 +21,15 @@ export {
export { Logger, LogLevel, LogLine } from "./tracing/logger"; export { Logger, LogLevel, LogLine } from "./tracing/logger";
export { type SyncSettings, DEFAULT_SETTINGS } from "./persistence/settings"; export { type SyncSettings, DEFAULT_SETTINGS } from "./persistence/settings";
export { rateLimit } from "./utils/rate-limit"; export { rateLimit } from "./utils/rate-limit";
export type { RelativePath, StoredDatabase } from "./persistence/database";
export type { export type {
FileSystemOperations, DocumentId,
FileSnapshot RelativePath,
} from "./file-operations/filesystem-operations"; StoredDatabase,
export type { PersistenceProvider } from "./persistence/persistence"; VaultUpdateId
} from "./persistence/database";
export type { FileSystemOperations } from "./file-operations/filesystem-operations";
export type { FileSnapshot } from "./snapshot";
export type { MetadataPersistenceProvider as PersistenceProvider } from "./persistence/metadata-persistence-provider";
export type { CursorSpan } from "./services/types/CursorSpan"; export type { CursorSpan } from "./services/types/CursorSpan";
export type { ClientCursors } from "./services/types/ClientCursors"; export type { ClientCursors } from "./services/types/ClientCursors";
export type { NetworkConnectionStatus } from "./types/network-connection-status"; export type { NetworkConnectionStatus } from "./types/network-connection-status";
@ -36,7 +39,7 @@ export type {
} from "./errors/errors"; } from "./errors/errors";
export type { MaybeOutdatedClientCursors } from "./types/maybe-outdated-client-cursors"; export type { MaybeOutdatedClientCursors } from "./types/maybe-outdated-client-cursors";
export { DocumentSyncStatus } from "./types/document-sync-status"; export { DocumentSyncStatus } from "./types/document-sync-status";
export { SyncClient } from "./sync-client"; export { SyncClient, type StoredClient } from "./sync-client";
export type { TextWithCursors, CursorPosition } from "reconcile-text"; export type { TextWithCursors, CursorPosition } from "reconcile-text";
export const debugging = { export const debugging = {

View file

@ -1,3 +1,4 @@
import type { RelativePath } from "./database";
import type { Logger } from "../tracing/logger"; import type { Logger } from "../tracing/logger";
import { globsToRegexes } from "../utils/globs-to-regexes"; import { globsToRegexes } from "../utils/globs-to-regexes";
import { isInternalPath } from "../utils/portable-path"; import { isInternalPath } from "../utils/portable-path";
@ -68,7 +69,7 @@ export class Settings {
); );
} }
public isIgnored(path: string): boolean { public isIgnored(path: RelativePath): boolean {
return ( return (
isInternalPath(path) || isInternalPath(path) ||
this.ignorePatterns.some((pattern) => pattern.test(path)) this.ignorePatterns.some((pattern) => pattern.test(path))
@ -111,17 +112,20 @@ export class Settings {
await this.saveData(next); await this.saveData(next);
this.settings = next; this.settings = next;
if (update.ignorePatterns !== undefined) if (update.ignorePatterns !== undefined) {
this.ignorePatterns = globsToRegexes( this.ignorePatterns = globsToRegexes(
next.ignorePatterns, next.ignorePatterns,
this.logger this.logger
); );
}
return [this.getSettings(), oldSettings] as const; return [this.getSettings(), oldSettings] as const;
}); });
// Listeners can themselves update settings. Never await them while // Listeners can themselves update settings. Never await them while
// holding a lock needed by the operation they invoke. // holding a lock needed by the operation they invoke.
if (notify) await this.onSettingsChanged.triggerAsync(...change); if (notify) {
await this.onSettingsChanged.triggerAsync(...change);
}
} }
} }

View file

@ -5,4 +5,4 @@ export type EventBatch = { headEventId: number,
/** /**
* Last event in this page; `head_event_id` is the vault's current head. * Last event in this page; `head_event_id` is the vault's current head.
*/ */
endEventId?: number, events: Array<EventRecord>, }; endEventId: number, events: Array<EventRecord>, };

View file

@ -18,7 +18,7 @@ isAuthenticated: boolean,
*/ */
mergeableFileExtensions: Array<string>, mergeableFileExtensions: Array<string>,
/** /**
* API version ensuring backwards & forwards compatibility between the client * API version that must match exactly between the client
* and server. * and server.
*/ */
supportedApiVersion: number, }; supportedApiVersion: number, };

View file

@ -0,0 +1,20 @@
import type { CursorPosition } from "reconcile-text";
import { hash } from "./utils/hash";
export interface FileSnapshot {
content: Uint8Array;
cursors?: CursorPosition[];
}
export interface HashedSnapshot extends FileSnapshot {
hash: string;
}
export async function hashSnapshot(
snapshot: FileSnapshot
): Promise<HashedSnapshot> {
// Own the bytes so later adapter mutations cannot invalidate the hash
const content = new Uint8Array(snapshot.content);
return { content, cursors: snapshot.cursors, hash: await hash(content) };
}

View file

@ -88,11 +88,11 @@ export class SyncHistory {
} }
/** /**
* Insert the entry at the beginning of the history list. If the entry * Insert the entry at the beginning of the history list. If the entry
* already in the list, it will get moved to the beginning and updated. * already in the list, it will get moved to the beginning and updated.
* *
* If the entry list is too long, the oldest entry will be removed. * If the entry list is too long, the oldest entry will be removed.
*/ */
public addHistoryEntry(entry: CommonHistoryEntry): void { public addHistoryEntry(entry: CommonHistoryEntry): void {
const historyEntry = { const historyEntry = {
...entry, ...entry,

View file

@ -1,3 +1,3 @@
import type { FileManifest } from "../services/types/FileManifest"; import type { DocumentId, RelativePath } from "../persistence/database";
export type FileManifestEntries = FileManifest["entries"]; export type FileManifestEntries = Record<DocumentId, RelativePath>;