[]
        
(Showing Draft Content)

DocumentServices

Class: DocumentServices<S, T>

Provides document services for collaborative operational transformation.

Type parameters

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

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DocumentServices<S, T>(config?)

Type parameters

Name
S
T

Parameters

Name Type
config? IDocConfig<S, T>

Properties

db

db: IDatabaseAdapter<S, T>

The database adapter for storing document data.

template The type of snapshot data.

template The type of operation data.


maxSubmitRetries

Optional maxSubmitRetries: number

The maximum number of retries for submitting an operation.

default undefined - No retry limit.


milestoneDb

milestoneDb: IMilestoneDatabaseAdapter<S>

The milestone database adapter for snapshot milestones.

template The type of snapshot data.


submitSnapshotBatchSize

submitSnapshotBatchSize: number

The batch size for submitting snapshots.

default 100

Methods

fetch

fetch(id, context?): Promise<ISnapshot<S>>

Fetches the latest snapshot of a document.

Parameters

Name Type Description
id string The ID of the document.
context? IContext -

Returns

Promise<ISnapshot<S>>

A promise resolving to the document snapshot.


fetchHistorySnapshot

fetchHistorySnapshot(id, version?, context?): Promise<ISnapshot<S>>

Fetches a historical snapshot of a document by version.

Parameters

Name Type Description
id string The ID of the document.
version? number -
context? IContext -

Returns

Promise<ISnapshot<S>>

A promise resolving to the historical snapshot.


getOps

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

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

Parameters

Name Type Description
id string The ID of the document.
from number The starting version.
to? number -
context? IContext -

Returns

Promise<IOp<T>[]>

A promise resolving to an array of operations.


on

on<K>(hookName, hook): void

Registers a hook for a specific event in the document services.

Type parameters

Name Type Description
K extends keyof IDocHookContext The type of the hook name, extending keyof IDocHookContext.

Parameters

Name Type Description
hookName K The name of the hook to register.
hook IHook<IDocHookContext[K]> The hook to register.

Returns

void


submit

submit(id, op, context?): Promise<IOp<T>[]>

Submits an operation to the document (must include an , , or field).

Parameters

Name Type Description
id string The ID of the document.
op IOp<T> The operation to submit.
context? IContext -

Returns

Promise<IOp<T>[]>

A promise resolving to the resulting operations.


use

use<K>(action, middleware): void

Registers a middleware for a specific action in the document services.

Type parameters

Name Type Description
K extends keyof IDocMiddlewareContext<S, T> The type of the action name, extending keyof IDocMiddlewareContext<S, T>.

Parameters

Name Type Description
action K The name of the action to associate with the middleware.
middleware IMiddleware<IDocMiddlewareContext<S, T>[K]> The middleware to register.

Returns

void