Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • T

Hierarchy

  • EventEmitter
    • Database

Index

Constructors

constructor

  • new Database<T>(dbname: string): Database<T>
  • Create a new database for a given Automerge document type.

    Type parameters

    • T

    Parameters

    • dbname: string

      The name of the database

    Returns Database<T>

Properties

onContactListChange

onContactListChange: Function

Accessors

all

  • Returns FreezeObject<IContact>[]

devices

  • Returns IDevice[]

documents

  • get documents(): string[]
  • Get an array of all document ids

    Returns string[]

root

  • Returns FreezeObject<ContactList>

  • Parameters

    Returns void

settings

  • get settings(): any
  • Returns any

Methods

addContact

  • addContact(key: string, name: string): Promise<string>
  • Add a contact.

    Parameters

    • key: string
    • name: string

    Returns Promise<string>

addDevice

  • addDevice(key: string): Promise<any>
  • Parameters

    • key: string

    Returns Promise<any>

addDocument

  • addDocument(docId: string, changeFn: ChangeFn<T | System>): Promise<string>
  • Parameters

    • docId: string
    • changeFn: ChangeFn<T | System>

    Returns Promise<string>

change

  • change<J>(docId: string, changeFn: ChangeFn<J>, message?: string): Promise<void>
  • Make a change to a document.

    Type parameters

    • J

    Parameters

    • docId: string

      The document ID

    • changeFn: ChangeFn<J>

      The Automerge change function to change the document.

    • Optional message: string

    Returns Promise<void>

changeContactList

  • changeContactList(changeFn: ChangeFn<ContactList>): Promise<void>
  • Parameters

    Returns Promise<void>

changeRoot

  • changeRoot(changeFn: ChangeFn<ContactList>): Promise<void>
  • Parameters

    Returns Promise<void>

deleteDevice

  • deleteDevice(id: string): Promise<void>
  • Parameters

    • id: string

    Returns Promise<void>

destroy

  • destroy(): Promise<void>
  • Returns Promise<void>

error

  • error(err: any): void
  • Parameters

    • err: any

    Returns void

getBlob

  • getBlob(id: string): Promise<Uint8Array>
  • Parameters

    • id: string

    Returns Promise<Uint8Array>

getContactByDiscoveryKey

  • getContactByDiscoveryKey(discoveryKey: string): IContact
  • Get contact by discovery key

    Parameters

    • discoveryKey: string

      the discovery key for this contact

    Returns IContact

getContactById

  • Parameters

    • id: string

    Returns IContact

getContacts

  • Returns IContact[]

getDocument

  • getDocument(docId: string): FreezeObject<unknown>
  • Parameters

    • docId: string

    Returns FreezeObject<unknown>

getDocumentIds

  • getDocumentIds(contact: IContact): string[]
  • Parameters

    Returns string[]

hasBlob

  • hasBlob(id: string): Promise<boolean>
  • Parameters

    • id: string

    Returns Promise<boolean>

isConnected

  • isConnected(contact: IContact): boolean
  • Is this contact currently connected to us? i.e., currently online and we have an open connection with them

    Parameters

    Returns boolean

    If the contact is currently connected

onDisconnect

  • onDisconnect(docId: any, peerId: any): Promise<void>
  • When a peer disconnects, call this function

    Parameters

    • docId: any

      A unique identifer for the document

    • peerId: any

      A unique identifier for the peer (should be the same called in onPeerConnect)

    Returns Promise<void>

onPeerConnect

  • onPeerConnect(peerId: string, docId: string, send: Function): ReceiveSyncMsg
  • When a peer connects, call this function

    Parameters

    • peerId: string
    • docId: string
    • send: Function

    Returns ReceiveSyncMsg

open

  • open(): Promise<any[]>
  • Open the database. This is called automatically when you create the instance and you don't need to call it.

    Returns Promise<any[]>

    When the database has been opened

save

  • save(docId: string): Promise<[string, void]>
  • Parameters

    • docId: string

    Returns Promise<[string, void]>

saveBlob

  • saveBlob(id: string, data: Uint8Array): PromiseExtended<string>
  • Parameters

    • id: string
    • data: Uint8Array

    Returns PromiseExtended<string>

Generated using TypeDoc