DataStore from @offline-protocol/mesh-sdk. These signatures match v0.27.0. Read the integration guide for prerequisites and complete usage.
Start the protocol and establish the MLS space first. A local flush is not peer acknowledgment. See replication semantics.
Methods on this page
createDocdeleteDocremoveDocremoveSpacefetchAttachmentFromsetInterestlistDocslistSpacesmapSetmapDeletemapGetlistPushlistDeletelistLengthtextInserttextDeletetextValuecounterIncrementcounterValuedocJsonexportRawflushflushAlldocSizewipeAllattachmentHashfetchAttachmentprovideAttachmentdeclineAttachment
createDoc
Creates a document, or does nothing if it already exists.deleteDoc
Drops this device’s copy, leaving the peers’ copies alone. Eviction rather than removal: it reclaims what the document occupies here and records nothing about the name, so the next version exchange with a replica that still holds it recreates and refills it. UseremoveDoc to remove content from the room.
removeDoc
Removes a document from every replica of its space. A replica holding an edit made concurrently with the removal keeps its copy and hands the document back, contents and all, so an edit beats a removal whichever happened first. That arrives as an ordinarydata_changed on a document you removed.
Every later call on the name rejects with InvalidState until
createDoc brings it back, on this device and on every device
that learns of the removal. data_doc_removed is the cue to close
whatever has the document open.
Removing a name this device does not hold does nothing. Re-using the
name afterwards is not fenced off: a replica that kept the old contents
past the removal merges them into the new document. Give new content a
fresh name.
removeSpace
Removes every document a space holds, from every replica of it.fetchAttachmentFrom
Asks one member of a group for the bytes behind a reference. A reference replicates to everybody and says nothing about who holds the bytes, so a group fetch names the member; the SDK does not try members in turn, because each miss costs the whole silence timeout. The bytes come back as frames under the group key, so no pairwise session with that member is needed, and they are bounded at 1 MiB. Anything larger travels over a 1:1 session, and the holder is told so at the call. UsefetchAttachment for a 1:1 space.
setInterest
The documents this device wants from its peers in one space. Each pattern is a document name, optionally ending in* to match a
prefix. ['*'] is everything and is the default; [] is nothing. At
most 32 patterns per space.
Toward a peer this is a request that saves the radio. Locally it is a
refusal, so a document outside it is never stored however it arrives,
which is what makes a narrowing mean something against a peer on an
older build.
Not persisted: declare it at launch, right after protocol.start() resolves. Narrowing does
not delete what is already held; widening asks the peers for what it
adds.
listDocs
The documents in a space.listSpaces
Every space that holds at least one document.mapSet
Sets a key in a map collection.mapDelete
Removes a key from a map collection.mapGet
Reads a key from a map collection, or null when it is absent.listPush
Appends to a list collection.listDelete
Deletes entries from a list collection.listLength
The number of entries in a list collection.textInsert
Inserts into a text collection.position is a character offset, not a byte offset.
textDelete
Deletes characters from a text collection.textValue
The contents of a text collection.counterIncrement
Adds to a counter collection. Negative amounts subtract.counterValue
The value of a counter collection.docJson
The document’s current state as plain JSON. Half of the escape hatch: an app can always take its data and leave, and this half needs no knowledge of the SDK to read.exportRaw
The document’s full history, base64-encoded. The other half of the escape hatch. PreferdocJson unless the
history itself is what you need.
flush
Persists pending edits to a document. Edits batch before they reach a record, so call this when the app must know a change survives a crash. The SDK also flushes on shutdown.flushAll
Persists pending edits to every open document.docSize
The compacted size of a document, in bytes.wipeAll
Deletes every record the data layer owns. Only needed when documents were pointed at a storage backend the app supplied:wipePersistedState() clears the default provider’s account
directory, which a custom backend is not inside. Skipping it there
leaves documents behind after the account that made them is gone.
Only durable once replication has stopped. A wipe records no removals,
because a logout has to leave a custom backend empty, so a peer cannot
tell a wiped space from one this device has never seen, and with the
engine running and sessions live its next version offer recreates and
refills every document, with no error and no event. Logout tears the
engine down anyway; call destroy() first if you are wiping for any
other reason, and only for as long as it stays stopped: the peer still
holds the documents, so they return when replication resumes. This
clears the device; removeSpace is what clears the room.
attachmentHash
The address of some bytes, in the spelling a reference uses. Write the result into a document withmapSet, which takes the value
as an object and encodes it for you:
fetchAttachment
Asks the peer a 1:1 space is named after for the bytes behind a reference. Pull rather than push, because a space may reference more bytes than a phone wants over Bluetooth: the decision to spend that is yours, per blob, when somebody opens one. The answer arrives later asdata_attachment_received or data_attachment_unavailable, never from
this call.
Group spaces are refused in this version: a blob rides a transfer to a
confirmed 1:1 session, and two group members need not have one.
provideAttachment
Answers a peer’sdata_attachment_requested with the bytes.
Rejects bytes that do not hash to hash, so a mistake reaches you while
you still have the file in hand rather than travelling the whole media
path to be refused on the other side.

