Struct ywasm::Transaction

source ·
pub struct Transaction { /* private fields */ }

Implementations§

source§

impl YTransaction

source

pub fn from_implicit( txn: &ImplicitTransaction ) -> Result<Option<Ref<'_, Self>>, JsValue>

source

pub fn from_implicit_mut( txn: &ImplicitTransaction ) -> Result<Option<RefMut<'_, Self>>, JsValue>

source

pub fn try_ref_from_js_value(value: &JsValue) -> Result<Ref<'_, Self>, JsValue>

source

pub fn try_mut_from_js_value( value: &JsValue ) -> Result<RefMut<'_, Self>, JsValue>

source

pub fn from_ref(txn: &TransactionMut<'_>) -> Self

source

pub fn as_ref(&self) -> &TransactionMut<'static>

source

pub fn as_mut(&mut self) -> Result<&mut TransactionMut<'static>, JsValue>

source§

impl YTransaction

source

pub fn before_state(&self) -> Map

Returns state vector describing the state of the document at the moment when the transaction began.

source

pub fn after_state(&self) -> Map

Returns state vector describing the current state of the document.

source

pub fn pending_structs(&self) -> Result<JsValue, JsValue>

source

pub fn pending_ds(&self) -> Option<Map>

Returns a unapplied delete set, that was received in one of the previous remote updates. This DeleteSet is waiting for a missing updates to arrive in order to be applied.

source

pub fn delete_set(&self) -> Map

Returns a delete set containing information about all blocks removed as part of a current transaction.

source

pub fn origin(&self) -> JsValue

source

pub fn get(&self, id: JsValue) -> Result<JsValue, JsValue>

Given a logical identifier of the collection (obtained via YText.id, YArray.id etc.), attempts to return an instance of that collection in the scope of current document.

Returns undefined if an instance was not defined locally, haven’t been integrated or has been deleted.

source

pub fn commit(&mut self) -> Result<(), JsValue>

Triggers a post-update series of operations without freeing the transaction. This includes compaction and optimization of internal representation of updates, triggering events etc. ywasm transactions are auto-committed when they are freed.

source

pub fn state_vector_v1(&self) -> Uint8Array

Encodes a state vector of a given transaction document into its binary representation using lib0 v1 encoding. State vector is a compact representation of updates performed on a given document and can be used by encode_state_as_update on remote peer to generate a delta update payload to synchronize changes between peers.

Example:

import YDoc from 'ywasm'

/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()

// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()

try {
    const localSV = localTxn.stateVectorV1()
    const remoteDelta = remoteTxn.diffV1(localSv)
    localTxn.applyV1(remoteDelta)
} finally {
    localTxn.free()
    remoteTxn.free()
}
source

pub fn diff_v1(&self, vector: Option<Uint8Array>) -> Result<Uint8Array, JsValue>

Encodes all updates that have happened since a given version vector into a compact delta representation using lib0 v1 encoding. If vector parameter has not been provided, generated delta payload will contain all changes of a current ywasm document, working effectively as its state snapshot.

Example:

import YDoc from 'ywasm'

/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()

// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()

try {
    const localSV = localTxn.stateVectorV1()
    const remoteDelta = remoteTxn.diffV1(localSv)
    localTxn.applyV1(remoteDelta)
} finally {
    localTxn.free()
    remoteTxn.free()
}
source

pub fn diff_v2(&self, vector: Option<Uint8Array>) -> Result<Uint8Array, JsValue>

Encodes all updates that have happened since a given version vector into a compact delta representation using lib0 v1 encoding. If vector parameter has not been provided, generated delta payload will contain all changes of a current ywasm document, working effectively as its state snapshot.

Example:

import YDoc from 'ywasm'

/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()

// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()

try {
    const localSV = localTxn.stateVectorV1()
    const remoteDelta = remoteTxn.diffV2(localSv)
    localTxn.applyV2(remoteDelta)
} finally {
    localTxn.free()
    remoteTxn.free()
}
source

pub fn apply_v1(&mut self, diff: Uint8Array) -> Result<(), JsValue>

Applies delta update generated by the remote document replica to a current transaction’s document. This method assumes that a payload maintains lib0 v1 encoding format.

Example:

import YDoc from 'ywasm'

/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()

// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()

try {
    const localSV = localTxn.stateVectorV1()
    const remoteDelta = remoteTxn.diffV1(localSv)
    localTxn.applyV1(remoteDelta)
} finally {
    localTxn.free()
    remoteTxn.free()
}
source

pub fn apply_v2(&mut self, diff: Uint8Array) -> Result<(), JsValue>

Applies delta update generated by the remote document replica to a current transaction’s document. This method assumes that a payload maintains lib0 v2 encoding format.

Example:

import YDoc from 'ywasm'

/// document on machine A
const localDoc = new YDoc()
const localTxn = localDoc.beginTransaction()

// document on machine B
const remoteDoc = new YDoc()
const remoteTxn = localDoc.beginTransaction()

try {
    const localSV = localTxn.stateVectorV1()
    const remoteDelta = remoteTxn.diffV2(localSv)
    localTxn.applyV2(remoteDelta)
} finally {
    localTxn.free()
    remoteTxn.free()
}
source

pub fn encode_update(&self) -> Uint8Array

source

pub fn encode_update_v2(&self) -> Uint8Array

Methods from Deref<Target = TransactionMut<'static>>§

source

pub fn doc(&self) -> &Doc

source

pub fn before_state(&self) -> &StateVector

Corresponding document’s state vector at the moment when current transaction was created.

source

pub fn after_state(&self) -> &StateVector

State vector of the transaction after [Transaction::commit] has been called.

source

pub fn delete_set(&self) -> &DeleteSet

Data about deletions performed in the scope of current transaction.

source

pub fn origin(&self) -> Option<&Origin>

Returns origin of the transaction if any was defined. Read-write transactions can get an origin assigned via Transact::try_transact_mut_with/Transact::transact_mut_with methods.

source

pub fn changed_parent_types(&self) -> &[BranchPtr]

Returns a list of root level types changed in a scope of the current transaction. This list is not filled right away, but as a part of TransactionMut::commit process.

source

pub fn encode_update_v1(&self) -> Vec<u8>

Encodes changes made within the scope of the current transaction using lib0 v1 encoding.

Document updates are idempotent and commutative. Caveats:

  • It doesn’t matter in which order document updates are applied.
  • As long as all clients receive the same document updates, all clients end up with the same content.
  • Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
source

pub fn encode_update_v2(&self) -> Vec<u8>

Encodes changes made within the scope of the current transaction using lib0 v2 encoding.

Document updates are idempotent and commutative. Caveats:

  • It doesn’t matter in which order document updates are applied.
  • As long as all clients receive the same document updates, all clients end up with the same content.
  • Even if an update contains known information, the unknown information is extracted and integrated into the document structure.
source

pub fn encode_update<E>(&self, encoder: &mut E)
where E: Encoder,

Encodes changes made within the scope of the current transaction.

Document updates are idempotent and commutative. Caveats:

  • It doesn’t matter in which order document updates are applied.
  • As long as all clients receive the same document updates, all clients end up with the same content.
  • Even if an update contains known information, the unknown information is extracted and integrated into the document structure.

Trait Implementations§

source§

impl Deref for YTransaction

§

type Target = TransactionMut<'static>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'doc> From<TransactionMut<'doc>> for YTransaction

source§

fn from(value: TransactionMut<'doc>) -> Self

Converts to this type from the input type.
source§

impl From<YTransaction> for JsValue

source§

fn from(value: YTransaction) -> Self

Converts to this type from the input type.
source§

impl FromWasmAbi for YTransaction

§

type Abi = u32

The wasm ABI type that this converts from when coming back out from the ABI boundary.
source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
source§

impl IntoWasmAbi for YTransaction

§

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary.
source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
source§

impl LongRefFromWasmAbi for YTransaction

§

type Abi = u32

Same as RefFromWasmAbi::Abi
§

type Anchor = Ref<'static, YTransaction>

Same as RefFromWasmAbi::Anchor
source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
source§

impl OptionFromWasmAbi for YTransaction

source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
source§

impl OptionIntoWasmAbi for YTransaction

source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
source§

impl RefFromWasmAbi for YTransaction

§

type Abi = u32

The wasm ABI type references to Self are recovered from.
§

type Anchor = Ref<'static, YTransaction>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
source§

impl RefMutFromWasmAbi for YTransaction

§

type Abi = u32

Same as RefFromWasmAbi::Abi
§

type Anchor = RefMut<'static, YTransaction>

Same as RefFromWasmAbi::Anchor
source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
source§

impl TryFromJsValue for YTransaction

§

type Error = JsValue

The type returned in the event of a conversion error.
source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl VectorFromWasmAbi for YTransaction

§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[YTransaction]>

source§

impl VectorIntoWasmAbi for YTransaction

§

type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi

source§

fn vector_into_abi(vector: Box<[YTransaction]>) -> Self::Abi

source§

impl WasmDescribe for YTransaction

source§

impl WasmDescribeVector for YTransaction

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.