Skip to main content
Module

x/earthstar/mod.browser.ts>IReplica

A specification and Javascript library for building online tools you can truly call your own.
Go to Latest
interface IReplica
implements IReplicaConfig
Re-export
import { type IReplica } from "https://deno.land/x/earthstar@v9.3.3/mod.browser.ts";

A replica of a share's data, used to read, write, and synchronise data to. Should be closed using the close method when no longer being used.

const myReplica = new Replica("+a.a123", Es4Validatior, new ReplicaDriverMemory());

Properties

replicaId: ReplicaId

The address of the share this replica belongs to.

formatValidator: IFormatValidator

The validator used to validate ingested documents.

replicaDriver: IReplicaDriver

Methods

isClosed(): boolean

Returns whether the replica is closed or not.

close(erase: boolean): Promise<void>

Closes the replica, preventing new documents from being ingested or events being emitted. Any methods called after closing will return ReplicaIsClosedError.

getMaxLocalIndex(): number

Returns the max local index of all stored documents

getDocsAfterLocalIndex(
historyMode: HistoryMode,
startAfter: LocalIndex,
limit?: number,
): Promise<Doc[]>
getAllDocs(): Promise<Doc[]>

Returns all documents, including historical versions of documents by other identities.

getLatestDocs(): Promise<Doc[]>

Returns latest document from every path.

getAllDocsAtPath(path: Path): Promise<Doc[]>

Returns all versions of a document by different authors from a specific path.

getLatestDocAtPath(path: Path): Promise<Doc | undefined>

Returns the most recently written version of a document at a path.

queryDocs(query?: Query): Promise<Doc[]>

Returns an array of docs for a given query.

const myQuery = {
  filter: {
    pathEndsWith: ".txt"
  },
  limit: 5,
};

const firstFiveTextDocs = await myReplica.queryDocs(myQuery);
queryPaths(query?: Query): Promise<Path[]>

Returns an array of all unique paths of documents returned by a given query.

queryAuthors(query?: Query): Promise<AuthorAddress[]>

Returns an array of all unique authors of documents returned by a given query.

set(keypair: AuthorKeypair, docToSet: DocToSet): Promise<IngestEvent>

Adds a new document to the replica. If a document signed by the same identity exists at the same path, it will be overwritten.

ingest(doc: Doc): Promise<IngestEvent>

Ingest an existing signed document to the replica.

overwriteAllDocsByAuthor(keypair: AuthorKeypair): Promise<number | ValidationError>

Overwrite every document from this author, including history versions, with an empty doc.