[]
        
(Showing Draft Content)

IDatabaseAdapter

Interface: IDatabaseAdapter<S, T>

Defines the interface for a database adapter in operational transformation.

Type parameters

Name Type Description
S unknown The type of snapshot data.
T unknown The type of operation data.

Implemented by

Table of contents

Methods

Methods

close

close(): Promise<void>

Closes the database connection.

Returns

Promise<void>

A promise that resolves when the database is closed.


commitOp

commitOp(id, op, document, options?): Promise<boolean>

Commits an operation to the database.

Parameters

Name Type Description
id string The document ID.
op IOp<T> The operation to commit.
document IDocument The document metadata.
options? unknown -

Returns

Promise<boolean>

A promise resolving to true if the operation was committed, false otherwise.


commitSnapshot

commitSnapshot(id, snapshot, options?): Promise<boolean>

Commits a snapshot to the database.

Parameters

Name Type Description
id string The document ID.
snapshot ICommitSnapshot<S> The snapshot to commit.
options? unknown -

Returns

Promise<boolean>

A promise resolving to true if the snapshot was committed, false otherwise.


getCommittedOpVersion

getCommittedOpVersion(id, to, op): Promise<null | number>

Retrieves the committed version of an operation, if it exists.

Parameters

Name Type Description
id string The document ID.
to number The ending version to check up to.
op IOp<unknown> The operation to verify.

Returns

Promise<null | number>

A promise resolving to the committed version or null if not committed.


getDocument

getDocument(id, options?): Promise<null | IDocument>

Retrieves document information by ID.

Parameters

Name Type Description
id string The document ID.
options? unknown -

Returns

Promise<null | IDocument>

A promise resolving to the document info or null if not found.


getFragment

getFragment(id, fragmentId, options?): Promise<null | { data: null | S ; version: number }>

Retrieves a specific fragment of a document by ID.

Parameters

Name Type Description
id string The document ID.
fragmentId string The ID of the fragment.
options? unknown -

Returns

Promise<null | { data: null | S ; version: number }>

| null>} Resolves to an object with fragment version and data, or null if the document does not exist. If the document exists but the fragment does not, data is null.


getOps

getOps(id, from, to?, options?): Promise<IOp<T>[]>

Retrieves operations between two versions (inclusive of 'from', exclusive of 'to').

Parameters

Name Type Description
id string The document ID.
from number The starting version.
to? number -
options? unknown -

Returns

Promise<IOp<T>[]>

A promise resolving to an array of operations.


getSnapshot

getSnapshot(id, options?): Promise<null | ISnapshot<S>>

Retrieves the snapshot of a document by ID.

Parameters

Name Type Description
id string The document ID.
options? unknown -

Returns

Promise<null | ISnapshot<S>>

A promise resolving to the snapshot or null if not found.