import { MultiformatReplica } from "https://deno.land/x/earthstar@v10.2.0/src/entries/universal.ts";
A replica holding 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 gardeningKeypair = await Crypto.generateShareKeypair("gardening");
const myReplica = new Replica({
driver: new ReplicaDriverMemory(gardeningKeypair.shareAddress),
config: {
"es.5": { shareSecret: gardeningKeypair.secret }
}
});
Constructors
Properties
The validator used to validate ingested documents.
Methods
Erases expired docs and dangling attachments
Returns the given array of documents with a new attachment
property merged in. The value of this property can be:
DocAttachment
undefined
(the associated document can have an attachment, but we don't have a copy)ValidationError
(the associated document can't have an attachment)
Closes the replica, preventing new documents from being ingested or events being emitted.
Any methods called after closing will return ReplicaIsClosedError
.
Returns all documents, including historical versions of documents by other identities.
Returns all versions of a document by different authors from a specific path.
Gets an attachment for a given document. Returns a ValidationError
if the given document can't have an attachment.
Returns a readable stream of replica events, such as new ingestions, document expirations, or the replica preparing to close.
Returns the most recently written version of a document at a path.
Returns latest document from every path.
Returns the max local index of all stored documents
Returns a readable stream of document events which match a given query. The events can represent existing documents, newly ingested documents, or expiring documents.
Ingest an existing signed document to the replica.
Ingest an attachment for a given document.
Returns whether the replica is closed or not.
Provide a callback to be triggered every time a replica event occurs.
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.
Returns an array of docs for a given query. ``` const myQuery = { filter: { pathEndsWith: ".txt" }, limit: 5, };
const firstFiveTextDocs = await myReplica.queryDocs(myQuery);
```
Returns an array of all unique paths of documents returned by a given query.
Adds a new document to the replica. If a document signed by the same identity exists at the same path, it will be overwritten.
Wipe all content from a document at a given path, and erase its attachment (if it has one).