This commit is contained in:
Andras Schmelczer 2026-09-26 20:43:31 +01:00
commit 0c75d3b4c2
2 changed files with 11 additions and 8 deletions

View file

@ -67,16 +67,17 @@ export class FileOperations {
return snapshot.content; return snapshot.content;
} }
public async snapshot(path: string): Promise<StoredSnapshot | undefined> {
const snapshot = await this.fs.read(path);
return snapshot && toStoredSnapshot(snapshot);
}
public async listFilesRecursively(): Promise<string[]> { public async listFilesRecursively(): Promise<string[]> {
return (await this.fs.listFilesRecursively()).filter( return (await this.fs.listFilesRecursively()).filter(
(path) => !isInternalPath(path) (path) => !isInternalPath(path)
); );
} }
public async snapshot(path: string): Promise<StoredSnapshot | undefined> {
const snapshot = await this.fs.read(path);
return snapshot && toStoredSnapshot(snapshot);
}
public async captureChange( public async captureChange(
change: LocalChange, change: LocalChange,

View file

@ -8,19 +8,21 @@ export type LocalChange = {
/** Identities at notification time, before a remote application can reuse paths. */ /** Identities at notification time, before a remote application can reuse paths. */
identities?: Record<string, string>; identities?: Record<string, string>;
} & ( } & (
| { type: "move"; oldPath: string; relativePath: string } | { type: "move"; oldPath: string; relativePath: string }
| { type: "create"; path: string; documentId?: string } | { type: "create"; path: string; documentId?: string }
| { type: "delete"; path: string } | { type: "delete"; path: string }
); );
export function unappliedChanges<T extends { changeId?: string }>( export function unappliedChanges<T extends { changeId?: string }>(
state: EngineState, state: EngineState,
changes: readonly T[] changes: readonly T[]
): T[] { ): T[] {
for (const change of changes) change.changeId ??= uuid(); for (const change of changes) change.changeId ??= uuid();
const applied = changes.findIndex( const applied = changes.findIndex(
(change) => change.changeId === state.lastAppliedLocalChangeId (change) => change.changeId === state.lastAppliedLocalChangeId
); );
return changes.slice(applied + 1); return changes.slice(applied + 1);
} }