Skip to main content
Module

x/earthstar/mod.ts>Replica

A specification and Javascript library for building online tools you can truly call your own.
Go to Latest
class Replica
implements IReplica
import { Replica } from "https://deno.land/x/earthstar@v9.3.3/mod.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());

Constructors

new
Replica(
share: ShareAddress,
validator: IFormatValidator,
)

Properties

private
_isClosed: boolean
private
eraseInterval: number
private
ingestLock: Lock<IngestEvent>
formatValidator: IFormatValidator

The validator used to validate ingested documents.

replicaDriver: IReplicaDriver
replicaId: ReplicaId

The address of the share this replica belongs to.

Methods

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.

deleteConfig(key: string): Promise<boolean>
getAllDocs(): Promise<Doc[]>

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

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

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

getConfig(key: string): Promise<string | undefined>
getDocsAfterLocalIndex(
historyMode: HistoryMode,
startAfter: LocalIndex,
limit?: number,
): Promise<Doc[]>
getLatestDocAtPath(path: Path): Promise<Doc | undefined>

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

getLatestDocs(): Promise<Doc[]>

Returns latest document from every path.

Returns the max local index of all stored documents

ingest(docToIngest: Doc): Promise<IngestEvent>

Ingest an existing signed document to the replica.

isClosed(): boolean

Returns whether the replica is closed or not.

listConfigKeys(): Promise<string[]>

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

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

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)

Returns an array of all unique paths 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.

setConfig(key: string, value: string): Promise<void>