diff --git a/src/json-crdt/file/File.ts b/src/json-crdt/file/File.ts index 15dd480931..92b68e5349 100644 --- a/src/json-crdt/file/File.ts +++ b/src/json-crdt/file/File.ts @@ -1,5 +1,5 @@ import {Model} from '../model'; -import {PatchLog} from '../history/PatchLog'; +import {Log} from '../log/Log'; import {printTree} from '../../util/print/printTree'; import {decodeModel, decodeNdjsonComponents, decodePatch, decodeSeqCborComponents} from './util'; import {Patch} from '../../json-crdt-patch'; @@ -42,11 +42,11 @@ export class File implements Printable { decodedModel = decodeModel(model); } } - let log: PatchLog | null = null; + let log: Log | null = null; if (history) { const [start, patches] = history; if (start) { - log = new PatchLog(() => decodeModel(start)); + log = new Log(() => decodeModel(start)); for (const patch of patches) log.end.applyPatch(decodePatch(patch)); } } @@ -74,12 +74,12 @@ export class File implements Printable { } public static fromModel(model: Model, options: FileOptions = {}): File { - return new File(model, PatchLog.fromNewModel(model), options); + return new File(model, Log.fromNewModel(model), options); } constructor( public readonly model: Model, - public readonly log: PatchLog, + public readonly log: Log, protected readonly options: FileOptions = {}, ) {} diff --git a/src/json-crdt/history/LocalHistoryCrud.ts b/src/json-crdt/history/LocalHistoryCrud.ts index 2a8d0fa79b..ca99d2a571 100644 --- a/src/json-crdt/history/LocalHistoryCrud.ts +++ b/src/json-crdt/history/LocalHistoryCrud.ts @@ -3,7 +3,7 @@ import {CborEncoder} from '../../json-pack/cbor/CborEncoder'; import type {CrudApi} from 'memfs/lib/crud/types'; import type {Locks} from 'thingies/es2020/Locks'; import type {Patch} from '../../json-crdt-patch'; -import type {PatchLog} from './PatchLog'; +import type {Log} from '../log/Log'; import type {LocalHistory} from './types'; export const genId = (octets: number = 8): string => { @@ -25,7 +25,7 @@ export class LocalHistoryCrud implements LocalHistory { protected readonly locks: Locks, ) {} - public async create(collection: string[], log: PatchLog): Promise<{id: string}> { + public async create(collection: string[], log: Log): Promise<{id: string}> { // TODO: Remove `log.end`, just `log` should be enough. const file = new File(log.end, log, this.fileOpts); const blob = file.toBinary({ @@ -39,7 +39,7 @@ export class LocalHistoryCrud implements LocalHistory { return {id}; } - public async read(collection: string[], id: string): Promise<{log: PatchLog; cursor: string}> { + public async read(collection: string[], id: string): Promise<{log: Log; cursor: string}> { const blob = await this.crud.get([...collection, id], STATE_FILE_NAME); const {log} = File.fromSeqCbor(blob); return { @@ -48,7 +48,7 @@ export class LocalHistoryCrud implements LocalHistory { }; } - public readHistory(collection: string[], id: string, cursor: string): Promise<{log: PatchLog; cursor: string}> { + public readHistory(collection: string[], id: string, cursor: string): Promise<{log: Log; cursor: string}> { throw new Error('Method not implemented.'); } diff --git a/src/json-crdt/history/SessionHistory.ts b/src/json-crdt/history/SessionHistory.ts index 526d8b2f99..16622973ba 100644 --- a/src/json-crdt/history/SessionHistory.ts +++ b/src/json-crdt/history/SessionHistory.ts @@ -3,7 +3,7 @@ import {FanOutUnsubscribe} from 'thingies/es2020/fanout'; import {InsValOp, Patch} from '../../json-crdt-patch'; import {ValNode} from '../nodes'; import {toSchema} from '../schema/toSchema'; -import {PatchLog} from './PatchLog'; +import {Log} from '../log/Log'; import {RedoItem, UndoItem, UndoRedoStack} from './UndoRedoStack'; class Undo implements UndoItem { @@ -15,7 +15,7 @@ class Redo implements RedoItem { } export class SessionHistory { - constructor(public readonly log: PatchLog) {} + constructor(public readonly log: Log) {} private readonly __onPatchRace = createRace(); diff --git a/src/json-crdt/history/__tests__/LocalHistoryCrud.spec.ts b/src/json-crdt/history/__tests__/LocalHistoryCrud.spec.ts index aed5d686ef..cf6443657d 100644 --- a/src/json-crdt/history/__tests__/LocalHistoryCrud.spec.ts +++ b/src/json-crdt/history/__tests__/LocalHistoryCrud.spec.ts @@ -2,7 +2,7 @@ import {memfs} from 'memfs'; import {NodeCrud} from 'memfs/lib/node-to-crud'; import {Locks} from 'thingies/es2020/Locks'; import {LocalHistoryCrud} from '../LocalHistoryCrud'; -import {PatchLog} from '../PatchLog'; +import {Log} from '../../log/Log'; import {Model} from '../../model'; const setup = async () => { @@ -25,7 +25,7 @@ test('can create a new document', async () => { model.api.root({ foo: 'spam', }); - const log = PatchLog.fromNewModel(model); + const log = Log.fromNewModel(model); const {id} = await local.create(['test'], log); expect(typeof id).toBe('string'); expect(id.length > 6).toBe(true); @@ -49,7 +49,7 @@ test('can delete a document', async () => { model.api.root({ foo: 'spam', }); - const log = PatchLog.fromNewModel(model); + const log = Log.fromNewModel(model); const {id} = await local.create(['test'], log); await local.read(['test'], id); await local.delete(['test'], id); diff --git a/src/json-crdt/history/types.ts b/src/json-crdt/history/types.ts index 91feef7eec..59fcce0054 100644 --- a/src/json-crdt/history/types.ts +++ b/src/json-crdt/history/types.ts @@ -1,5 +1,5 @@ import type {Patch} from '../../json-crdt-patch'; -import type {PatchLog} from '../history/PatchLog'; +import type {Log} from '../log/Log'; import type {Model} from '../model'; /** @@ -37,16 +37,16 @@ export interface RemoteHistory { } export interface LocalHistory { - create(collection: string[], log: PatchLog): Promise<{id: string}>; - read(collection: string[], id: string): Promise<{log: PatchLog; cursor: string}>; - readHistory(collection: string[], id: string, cursor: string): Promise<{log: PatchLog; cursor: string}>; + create(collection: string[], log: Log): Promise<{id: string}>; + read(collection: string[], id: string): Promise<{log: Log; cursor: string}>; + readHistory(collection: string[], id: string, cursor: string): Promise<{log: Log; cursor: string}>; update(collection: string[], id: string, patches: Patch[]): Promise; delete(collection: string[], id: string): Promise; } export interface EditingSessionHistory { load(id: string): Promise; - loadHistory(id: string): Promise; + loadHistory(id: string): Promise; undo(id: string): Promise; redo(id: string): Promise; } diff --git a/src/json-crdt/history/PatchLog.ts b/src/json-crdt/log/Log.ts similarity index 96% rename from src/json-crdt/history/PatchLog.ts rename to src/json-crdt/log/Log.ts index 50ee57af00..e39c44f4b1 100644 --- a/src/json-crdt/history/PatchLog.ts +++ b/src/json-crdt/log/Log.ts @@ -6,7 +6,7 @@ import {Model} from '../model'; import {first, next} from '../../util/trees/util'; import type {Printable} from '../../util/print/types'; -export class PatchLog implements Printable { +export class Log implements Printable { /** * Creates a `PatchLog` instance from a newly JSON CRDT model. Checks if * the model API buffer has any initial operations applied, if yes, it @@ -16,9 +16,9 @@ export class PatchLog implements Printable { * `Model.withLogicalClock()` or `Model.withServerClock()`. * @returns A new `PatchLog` instance. */ - public static fromNewModel(model: Model): PatchLog { + public static fromNewModel(model: Model): Log { const clock = model.clock.clone(); - const log = new PatchLog(() => new Model(clock)); + const log = new Log(() => new Model(clock)); const api = model.api; if (api.builder.patch.ops.length) log.end.applyPatch(api.flush()); return log; diff --git a/src/json-crdt/history/__tests__/PatchLog.spec.ts b/src/json-crdt/log/__tests__/Log.spec.ts similarity index 96% rename from src/json-crdt/history/__tests__/PatchLog.spec.ts rename to src/json-crdt/log/__tests__/Log.spec.ts index 4eb694dce4..a59578cc6d 100644 --- a/src/json-crdt/history/__tests__/PatchLog.spec.ts +++ b/src/json-crdt/log/__tests__/Log.spec.ts @@ -1,10 +1,10 @@ import {Model} from '../../model'; -import {PatchLog} from '../PatchLog'; +import {Log} from '../Log'; const setup = (view: unknown) => { const model = Model.withServerClock(); model.api.root(view); - const log = PatchLog.fromNewModel(model); + const log = Log.fromNewModel(model); return {log}; };