Document

class Document(key: String, options: Document.Options = Options()) : Closeable, Attachable

A CRDT-based data type. We can represent the model of the application and edit it even while offline.

A single-threaded, Closeable is used as default. Therefore you need to close the document, when the document is no longer needed. If you provide your own dispatcher, it is up to you to decide close is needed or not. snapshotDispatcher can be set differently from dispatcher, as snapshot operation can be much heavier than other operations.

Constructors

Link copied to clipboard
constructor(key: String, options: Document.Options = Options())

Types

Link copied to clipboard
data class BroadcastOptions(val maxRetries: Int = Int.MAX_VALUE)

BroadcastOptions are the options to create a new broadcast.

Link copied to clipboard
sealed interface Event : ResourceEvent
Link copied to clipboard
data class Options(val disableGC: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard
val events: SharedFlow<Document.Event>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val presences: StateFlow<Presences>

Functions

Link copied to clipboard
open override fun applyStatus(status: ResourceStatus)
Link copied to clipboard
open override fun close()
Link copied to clipboard
fun events(targetPath: String): Flow<Document.Event>

Subscribes to events on the document with the specific targetPath.

Link copied to clipboard
fun garbageCollect(minSyncedVersionVector: VersionVector): Int

Deletes elements that were removed before the given time.

Link copied to clipboard

getDocSize returns the size of this document.

Link copied to clipboard
open override fun getKey(): String

getKey returns the key of this document.

Link copied to clipboard

getMaxSizePerDocument gets the maximum size of this document.

Link copied to clipboard
suspend fun getRoot(): JsonObject

Returns a new proxy of cloned root.

Link copied to clipboard

getSchemaRules gets the schema rules of this document.

Link copied to clipboard
open override fun getStatus(): ResourceStatus

getStatus returns the status of this document.

Link copied to clipboard
suspend fun getValueByPath(path: String): JsonElement?

Returns the JsonElement corresponding to the path.

Link copied to clipboard

getVersionVector returns the version vector of document

Link copied to clipboard
open override fun hasLocalChanges(): Boolean

hasLocalChanges returns whether this document has local changes or not.

Link copied to clipboard
open override fun publish(event: ResourceEvent)

publish publishes an event to notify observers about changes in this resource.

Link copied to clipboard
suspend fun publishEvent(event: Document.Event)
Link copied to clipboard
open override fun setActor(actorID: ActorID)

Sets actorID into this document. This is also applied in the localChanges the document has.

Link copied to clipboard

setMaxSizePerDocument sets the maximum size of this document.

Link copied to clipboard
fun setSchemaRules(rules: List<Rule>)

setSchemaRules sets the schema rules of this document.

Link copied to clipboard
fun toJson(): String
Link copied to clipboard
fun updateAsync(message: String? = null, updater: suspend (root: JsonObject, presence: DocPresence) -> Unit): Deferred<OperationResult>

Executes the given updater to update this document.