Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Datastore

A multi-user collaborative datastore. The namespace for the Datastore class statics.

Notes

A store is structured in a maximally flat way using a hierarchy of tables, records, and fields. Internally, the object graph is synchronized among all users via CRDT algorithms.

https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type https://hal.inria.fr/file/index/docid/555588/filename/techreport.pdf

Hierarchy

  • Datastore

Implements

Index

Type aliases

Static Change

Change: object

A type alias for a store change.

Type declaration

Static Context

Context: Readonly<Private.MutableContext>
internal

Static DataLocation

DataLocation: object

A base type for describing the location of data in a datastore, to be consumed by some object. The only requirement is that it has a datastore object. Objects extending from this will, in general, have some combination of table, record, and field locations.

Type declaration

Static FieldLocation

FieldLocation<S, F>: RecordLocation<S> & object

An interface for referring to a specific field in a datastore.

Notes

The field must exist in the schema.

Type parameters

  • S: Schema

  • F: keyof S["fields"]

Static MutableChange

MutableChange: object
internal

Type declaration

Static MutablePatch

MutablePatch: object
internal

Type declaration

Static Patch

Patch: object

A type alias for a store patch.

Type declaration

Static RecordLocation

RecordLocation<S>: TableLocation<S> & object

An interface for referring to a specific record in a datastore.

Type parameters

Static TableLocation

TableLocation<S>: object

An interface for referring to a specific table in a datastore.

Type parameters

Type declaration

Static Transaction

Transaction: object

An object representing a datastore transaction.

Type declaration

Static TransactionIdFactory

TransactionIdFactory: function

A factory function for generating a unique transaction id.

Type declaration

    • (version: number, storeId: number): string
    • Parameters

      • version: number
      • storeId: number

      Returns string

Static TransactionType

TransactionType: "transaction" | "undo" | "redo"

A type alias for kinds of transactions.

Constructors

Private constructor

Properties

Private _adapter

_adapter: IServerAdapter | null

Private _cemetery

_cemetery: object

Type declaration

  • [id: string]: number

Private _changed

_changed: Signal<Datastore, IChangedArgs> = new Signal<Datastore, Datastore.IChangedArgs>(this)

Private _context

_context: Context

Private _disposed

_disposed: boolean = false

Private _tables

_tables: BPlusTree<Table<Schema>>

Private _transactionIdFactory

_transactionIdFactory: TransactionIdFactory

Private _transactionQueue

_transactionQueue: LinkedList<[object, "transaction" | "undo" | "redo"]> = new LinkedList<[Datastore.Transaction, Datastore.TransactionType]>()

Accessors

adapter

changed

  • A signal emitted when changes are made to the store.

    Notes

    This signal is emitted either at the end of a local mutation, or after a remote mutation has been applied. The storeId can be used to determine its source.

    The payload represents the set of local changes that were made to bring the store to its current state.

    Complexity

    O(1)

    Returns ISignal<Datastore, IChangedArgs>

id

  • get id(): number

inTransaction

  • get inTransaction(): boolean

isDisposed

  • get isDisposed(): boolean

version

  • get version(): number
  • The current version of the datastore.

    Notes

    This version is automatically increased for each transaction to the store. However, it might not increase linearly (i.e. it might make jumps).

    Complexity

    O(1)

    Returns number

Methods

Private _finalizeTransaction

  • _finalizeTransaction(): void
  • Finalize the context state for a transaction in progress.

    throws

    An exception if no transaction is in progress.

    Returns void

Private _initTransaction

  • _initTransaction(id: string, newVersion: number): void
  • Reset the context state for a new transaction.

    throws

    An exception if a transaction is already in progress.

    Parameters

    • id: string

      The id of the new transaction.

    • newVersion: number

      The version of the datastore after the transaction.

    Returns void

Private _onRedo

Private _onRemoteTransaction

Private _onUndo

Private _processQueue

  • _processQueue(): void

Private _processTransaction

Private _queueTransaction

beginTransaction

  • beginTransaction(): string
  • Begin a new transaction in the store.

    throws

    An exception if a transaction is already in progress.

    Notes

    This will allow the state of the store to be mutated thorugh the update method on the individual tables.

    After the updates are completed, endTransaction should be called.

    Returns string

    The id of the new transaction

dispose

  • dispose(): void

endTransaction

  • endTransaction(): void
  • Completes a transaction.

    Notes

    This completes a transaction previously started with beginTransaction. If a change has occurred, the changed signal will be emitted.

    Returns void

get

  • get<S>(schema: S): Table<S>
  • Get the table for a particular schema.

    throws

    An exception if no table exists for the given schema.

    Complexity

    O(log32 n)

    Type parameters

    Parameters

    • schema: S

      The schema of interest.

    Returns Table<S>

    The table for the specified schema.

iter

processMessage

  • processMessage(msg: Message): void

redo

  • redo(transactionId: string): Promise<void>
  • Redo a patch that was previously undone.

    throws

    An exception if redo is called during a mutation, or if no server adapter has been set for the datastore.

    Notes

    If changes are made, the changed signal will be emitted before the promise resolves.

    Parameters

    • transactionId: string

      The transaction to redo.

    Returns Promise<void>

    A promise which resolves when the action is complete.

toString

  • toString(): string

undo

  • undo(transactionId: string): Promise<void>
  • Undo a patch that was previously applied.

    throws

    An exception if undo is called during a mutation, or if no server adapter has been set for the datastore.

    Notes

    If changes are made, the changed signal will be emitted before the promise resolves.

    Parameters

    • transactionId: string

      The transaction to undo.

    Returns Promise<void>

    A promise which resolves when the action is complete.

Static create

  • Create a new datastore.

    throws

    An exception if any of the schema definitions are invalid.

    Parameters

    • options: IOptions

      The options for creating the datastore

    Returns Datastore

    A new datastore table.

Static getField

Static getRecord

Static getTable

Static listenField

  • listenField<S, F>(datastore: Datastore, loc: FieldLocation<S, F>, slot: function, thisArg?: any): IDisposable
  • Listen to changes in a fields in a table. Changes to other tables, other records in the same table, and other fields in the same record are ignored.

    Type parameters

    • S: Schema

    • F: keyof S["fields"]

    Parameters

    • datastore: Datastore
    • loc: FieldLocation<S, F>
    • slot: function
        • (source: Datastore, args: S["fields"][F]["ChangeType"]): void
        • Parameters

          • source: Datastore
          • args: S["fields"][F]["ChangeType"]

          Returns void

    • Optional thisArg: any

    Returns IDisposable

    an IDisposable that can be disposed to remove the listener.

Static listenRecord

  • Listen to changes in a record in a table. Changes to other tables and other records in the same table are ignored.

    Type parameters

    Parameters

    Returns IDisposable

    an IDisposable that can be disposed to remove the listener.

Static listenTable

Static updateField

  • updateField<S, F>(datastore: Datastore, loc: FieldLocation<S, F>, update: S["fields"][F]["UpdateType"]): void

Static updateRecord

Static updateTable

Static withTransaction

  • withTransaction(datastore: Datastore, update: function): string
  • A helper function to wrap an update to the datastore in calls to beginTransaction and endTransaction.

    Parameters

    • datastore: Datastore
    • update: function
        • (id: string): void
        • Parameters

          • id: string

          Returns void

    Returns string

    the transaction ID.

    Notes

    If the datastore is already in a transaction, this does not attempt to start a new one, and returns an empty string for the transaction id. This allows for transactions to be composed a bit more easily.

Generated using TypeDoc